Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/tadbirlar-jadvali

Event schedule

Medium 2000 ms 128 MB 45%
Share

$n$ events are planned in one hall: the $i$-th starts at time $s_{i}$ and ends at time $e_{i}$. Only one event can take place in the hall at a time; the next one may start at the moment the previous one ends. Find the largest number of events that can be held.

Events on a time axis and the largest set of non-overlapping events

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains two integers: $s_{i}$ and $e_{i}$.

Output

One integer — the largest number of events that can be held.

Note

$1 \le n \le 10^{5}$
$0 \le s_{i} \lt e_{i} \le 10^{9}$

Examples

Input #1
3
1 3
2 5
3 9
Output #1
2
Input #2
4
1 2
2 3
3 4
1 4
Output #2
3

Sign in to submit a solution

Signing up is free and takes a minute.