AtCoder Beginner Contest 103
D
Islands War
AtCoder
⌀ 1278
原题
← C→
翻译中…

Problem Statement

翻译中…

There are $N$ islands lining up from west to east, connected by $N-1$ bridges.

翻译中…

The $i$-th bridge connects the $i$-th island from the west and the $(i+1)$-th island from the west.

翻译中…

One day, disputes took place between some islands, and there were $M$ requests from the inhabitants of the islands:

翻译中…

Request $i$: A dispute took place between the $a_i$-th island from the west and the $b_i$-th island from the west. Please make traveling between these islands with bridges impossible.

翻译中…

You decided to remove some bridges to meet all these $M$ requests.

翻译中…

Find the minimum number of bridges that must be removed.

翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $2 \leq N \leq 10^5$
  • $1 \leq M \leq 10^5$
  • $1 \leq a_i < b_i \leq N$
  • All pairs $(a_i, b_i)$ are distinct.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N M
a_1 b_1
a_2 b_2
:
a_M b_M

翻译中…

Output

翻译中…

Print the minimum number of bridges that must be removed.

翻译中…

样例

Input #1
5 2
1 4
2 5
Output #1
1
The requests can be met by removing the bridge connecting the second and third islands from the west.
Input #2
9 5
1 8
2 7
3 5
4 6
7 9
Output #2
2
Input #3
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
Output #3
4
题目信息
题号
abc103_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。