IntermediateRating 1300
Longest Chain of Pairs
A pair (c, d) can follow (a, b) when b < c. Choose pairs in any order to build the longest chain and print its length.
Input
n; then n lines 'a b' with a < b.
Output
One integer.
Sample 1
Input
3 1 2 2 3 3 4
Output
2
Sample 2
Input
3 1 2 7 8 4 5
Output
3
Output appears here