#ABC103D. [ABC103D] Islands War

[ABC103D] Islands War

提示:该题测试数据补录中,暂不支持评测提交。

No testdata at current.

No submission language available for this problem.

Score : 400400 points

Problem Statement

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

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

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

Request ii: A dispute took place between the aia_i-th island from the west and the bib_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 MM requests.

Find the minimum number of bridges that must be removed.

Constraints

  • All values in input are integers.
  • 2≤N≤1052 \leq N \leq 10^5
  • 1≤M≤1051 \leq M \leq 10^5
  • 1≤ai<bi≤N1 \leq a_i < b_i \leq N
  • All pairs (ai,bi)(a_i, b_i) are distinct.

Input

Input is given from Standard Input in the following format:

NN MM

a1a_1 b1b_1

a2a_2 b2b_2

::

aMa_M bMb_M

Output

Print the minimum number of bridges that must be removed.

5 2
1 4
2 5
1

The requests can be met by removing the bridge connecting the second and third islands from the west.

9 5
1 8
2 7
3 5
4 6
7 9
2
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
4