시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB21161575.000%

문제

Given n open intervals (a1, b1), (a2, b2), ..., (an, bn) on the number line, each representing start and end times of some activity requiring the same resource, the goal is to find the largest number of these intervals so that no two of them overlap.

입력

The input will contain multiple test cases. Each test case starts with a single line containing a positive integer, n ≤ 50, indicating the number of intervals. The next n lines each contain a pair of positive integers separated by one or more blanks. Each pair of integers represents one interval. The end-of-input is denoted by a line containing 0.

출력

For each test case print the largest number of intervals that do not overlap.

예제 입력 1

5
10 12
2 6
5 8
3 9
1 4
2
1 3
3 5
0

예제 출력 1

3
2