Skip to content
UPEEC

Workshop Scheduling

Medium#greedy#sorting#intervals· solved by 0 · time limit 2.0 s

UPEEC has nn workshop slots, each with a start and end time, but only one hall. A workshop can start exactly when the previous one ends. What is the maximum number of workshops you can hold?

Input

nn, then nn lines start end (start < end).

Output

The maximum number of workshops.

Constraints

1≤n≤1051 \le n \le 10^5

Sample 1

Input

3
1 3
2 5
4 6

Output

2

Sample 2

Input

4
1 2
2 3
3 4
1 4

Output

3

Sign in or join free to run and submit your solution.