Time limit
1s
Memory limit
128 MB
On a two-dimensional coordinate plane, there are two distinct lines L1 and L2 parallel to the x-axis, and several segments connecting the two lines. This problem considers only segment sets satisfying the following conditions.
The figure below shows one segment set satisfying these conditions. If the segments are divided into X={A, C, E, F, G} (solid lines) and Y={B, D, H} (dotted lines), no two segments inside the same set cross.

From the given set, choose some segments and arrange them as a list (s1, s2, ..., sk). If every adjacent pair si and si+1 (1 <= i < k) crosses, the list is called a segment chain. The length of a segment chain is the number of segments in it.
Given a segment set satisfying the conditions above, find the maximum possible length of a segment chain.
The first line contains the number of segments N. N is between 1 and 100,000, inclusive.
Each of the next N lines contains one segment. A line gives the x-coordinate of the endpoint on L1 followed by the x-coordinate of the endpoint on L2. Every coordinate is an integer between 1 and 1,000,000, inclusive.
Print the maximum possible length of a segment chain on the first line.