Tiling Up Blocks

No attempts yetTime limit1sMemory limit128 MB

Problem

Michael the Kid got a game set from his grandparent as a birthday gift. The box holds nn tiling blocks, and every block has the shape below.

Figure 1: a tiling block with parameters (3,2)(3, 2).

Every block carries two parameters (,m)(\ell, m). The upper face has \ell protruding knobs on the left and mm protruding knobs in the middle, and the bottom face is carved with \ell dens on the left and mm dens in the middle at the matching spots.

An (,m)(\ell, m) block clearly sits on another (,m)(\ell, m) block, and that is not the only legal placement. An (,m)(\ell, m) block can be tiled upon an (,m)(\ell', m') block if and only if \ell \ge \ell' and mmm \ge m'.

You are given a box B={b1,b2,,bn}B = \{b_1, b_2, \dots, b_n\} of nn blocks, where block bib_i has parameters (i,mi)(\ell_i, m_i). Report how many blocks the tallest tower built from BB contains.

Input

The input lists several game boxes back to back. Each box starts with the integer nn, the number of blocks inside it. The next nn lines each hold two integers, the left parameter i\ell_i and the middle parameter mim_i of the ii-th block.

nn is at most 1000010\,000, and i\ell_i and mim_i lie between 11 and 100100. A value of n=0n = 0 marks the end of the input.

Output

For each box, print on its own line how many blocks the tallest tower built from that box contains. After the last box, print a single star * on a line of its own.