Maximum non-intersecting segments

Given n segments of the form [l; r] where both endpoints are inclusive, you are asked to calculate the maximum number of segments that have no intersection.
Note that segments having their endpoints at the same coordinates are not considered to be intersecting.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ ) - the number of segments.
The next n lines contain two space separated integers and .

Output

The program should print the maximum number of non-intersecting segments.

Examples

Input
Output
3 3 5 2 4 4 8
2
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue