#P469. 【例85.2】 区间调度问题

【例85.2】 区间调度问题

Description

The school has nn activities scheduled in the coming days, all of which require the use of the school's auditorium. At any given time, the auditorium can only be used by one activity. Due to time conflicts between some activities, the school office staff has to let some activities use other classrooms instead of the auditorium.
Given the start time beginibegin_i and end time endiend_i (begini<endibegin_i < end_i) for each of the nn activities, help the office staff arrange as many activities as possible to use the auditorium.

Input Format

The first line contains an integer nn (n1000n ≤ 1000).
The next nn lines each contain two integers: the first is beginibegin_i and the second is endiend_i (begini<endi32767begin_i < end_i ≤ 32767).

Output Format

Output the maximum number of activities that can be arranged.

Sample

11
3 5
1 4
12 14
8 12
0 6
8 11
6 10
5 7
3 8
5 9
2 13
4