#t367. 整数区间

整数区间

Integer Intervals

Problem Description

Write a program to do the following:

  1. Read from input the number of closed intervals and their descriptions;
  2. Find a set containing the fewest elements such that for every interval, at least one integer belongs to the set. Output the number of elements in that set.

Input Format

The first line contains the number of intervals n (1≤n≤10000)n\ (1\le n\le 10000). The following nn lines each contain two integers a,ba,b separated by a space, 0≤a≤b≤100000\le a\le b\le 10000, representing the start and end of an interval.

Output Format

Output one line with the number of elements in the set, such that for every interval at least one integer belongs to it, and the set has the minimum number of elements.

Sample Input

4
3 6
2 4
0 2
4 7

Sample Output

2

Constraints

1≤n≤100001\le n\le 10000, 0≤a≤b≤100000\le a\le b\le 10000.

Time limit 1s, memory limit 1024KiB for each test case.