output_description: Print the minimum number of bridges that must be removed.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      a_1 b_1
      a_2 b_2
      :
      a_M b_M
attempt: # 方針　もっとも近い敵でない島の集まりを調べると区間スケジュール問題となる。
  # 一列に並んでいるので飛んだ島とは繋げない
  # 橋の取り壊しの最小値というが、分割としてはもっとも番号の若いものまでしか無理である。
  # 最近接の敵である島の数字をもつ配列を考える。
  N, M = (int(_) for _ in input().split())
  mostNeightborOpponent = [N + 1 for _ in range(N)]
  # print(mostNeightborOpponent)
  for i in range(M):
      a, b = (int(_) for _ in input().split())
      if mostNeightborOpponent[a - 1] > b:
          mostNeightborOpponent[a - 1] = b
  # print(mostNeightborOpponent)
  # island:・・・島|島・・・の右の島のindex
  island = 1
  bridgeWillBreak = 0
  
  while island < N:
      minOpIsland = mostNeightborOpponent[island - 1]
      for i in range(island - 1, N):
          if minOpIsland > mostNeightborOpponent[i]:
              minOpIsland = mostNeightborOpponent[i]
      # print(minOpIsland)
      island = minOpIsland
      if island >= N:
          break
      bridgeWillBreak += 1
  
  print(bridgeWillBreak)
  
problem_description: 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.
samples: [{"input": "5 2\n    1 4\n    2 5", "output": "1\n    \n\nThe requests can be met by removing the bridge connecting the second and third\nislands from the west.\n\n* * *"}, {"input": "9 5\n    1 8\n    2 7\n    3 5\n    4 6\n    7 9", "output": "2\n    \n\n* * *"}, {"input": "5 10\n    1 2\n    1 3\n    1 4\n    1 5\n    2 3\n    2 4\n    2 5\n    3 4\n    3 5\n    4 5", "output": "4"}]