from operator import itemgetter



def main():

  N, M = list(map(int, input().split()))

  ab = [tuple(map(int, input().split())) for _ in range(M)]

  ab.sort(key=itemgetter(1))

  east_island = ab[0][1]

  answer = 1



  for i, j in ab:

      if i >= east_island:

          answer += 1

          east_island = j



  print(answer)





if __name__ == '__main__':

    main()
import sys

from operator import itemgetter

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

 

def main():

    N, M = list(map(int, readline().split()))

    ab = list(map(int, read().split()))

    ab = sorted(zip(ab, ab), key=itemgetter(1))

 

    east_island = ab[0][1]

    answer = 1

 

    for i, j in ab:

        if i >= east_island:

            answer += 1

            east_island = j

 

    print(answer)

 

 

if __name__ == '__main__':

    main()
from operator import itemgetter


def main():
    N, M = list(map(int, input().split()))
    ab = [tuple(map(int, input().split())) for _ in range(M)]
    ab.sort(key=itemgetter(1))
    east_island = ab[0][1]
    answer = 1
    for i, j in ab:
        if i >= east_island:
            answer += 1
            east_island = j
    print(answer)


if __name__ == "__main__":
    main()

import sys
from operator import itemgetter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, M = list(map(int, readline().split()))
    ab = list(map(int, read().split()))
    ab = sorted(zip(ab, ab), key=itemgetter(1))
    east_island = ab[0][1]
    answer = 1
    for i, j in ab:
        if i >= east_island:
            answer += 1
            east_island = j
    print(answer)


if __name__ == "__main__":
    main()

+import sys + +read = sys.stdin.read +readline = sys.stdin.readline +readlines = sys.stdin.readlines -    N, M = list(map(int, input().split())) -    ab = [tuple(map(int, input().split())) for _ in range(M)] -    ab.sort(key=itemgetter(1)) +    N, M = list(map(int, readline().split())) +    ab = list(map(int, read().split())) +    ab = sorted(zip(ab, ab), key=itemgetter(1))