On the beach!

When a summer apartment is advertised with a large On the beach!, hardly anyone believes that it will be true. Therefore, the owners of several apartment buildings (parallel to the beach but not on the beachfront) have decided to build underground passageways (perpendicular to the beach) connecting all buildings with the sand. Thus, they believe, customers will be happier. Since building these passageways is not cheap, first they want to know how many tunnels would be necessary at the very least. For example, for the configuration of buildings below (where buildings on the beachfront have been omitted) four tunnels are needed. Input Input consists of a series of test cases. Each case begins with a line with the number N of buildings (1 ≤ N ≤ 100,000). There follow N lines, each containing two integers representing the westernmost (Wi) and easternmost end (Ei) of each building, with Wi < Ei, measured in meters from the westernmost end of the beach. All these measures are integers between 0 and 109. Input will end with a case without buildings, which should not be processed. Output For each test case a line will be written with the minimum number of passageways that have to be built. Passageways must be 1 meter wide and to be useful for a building they must be completely beneath it as they pass through. Sample Input 4 14 6 15 2 10 12 20 2 14 48 2 14 38 0

2/2 Sample Output 2 2 1