import sys

from operator import itemgetter

input = sys.stdin.readline



n,m = list(map(int,input().split()))

li = [list(map(int,input().split())) for _ in range(m)]



ans = 0

now = -1



li.sort(key = itemgetter(1))



for i in range(m):

    if li[i][0] <= now and li[i][1] > now:

        pass

    else:

        ans += 1

        now = li[i][1] - 1



print(ans)

import sys

input = sys.stdin.readline



n,m = list(map(int,input().split()))

li = [list(map(int,input().split())) for _ in range(m)]



ans = 0

now = -1



li.sort(key = lambda x:x[1])



for i in range(m):

    if li[i][0] > now or li[i][1] <= now:

        ans += 1

        now = li[i][1] - 1



print(ans)

import sys
from operator import itemgetter

input = sys.stdin.readline
n, m = list(map(int, input().split()))
li = [list(map(int, input().split())) for _ in range(m)]
ans = 0
now = -1
li.sort(key=itemgetter(1))
for i in range(m):
    if li[i][0] <= now and li[i][1] > now:
        pass
    else:
        ans += 1
        now = li[i][1] - 1
print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
li = [list(map(int, input().split())) for _ in range(m)]
ans = 0
now = -1
li.sort(key=lambda x: x[1])
for i in range(m):
    if li[i][0] > now or li[i][1] <= now:
        ans += 1
        now = li[i][1] - 1
print(ans)

-from operator import itemgetter -li.sort(key=itemgetter(1)) +li.sort(key=lambda x: x[1]) -    if li[i][0] <= now and li[i][1] > now: -        pass -    else: +    if li[i][0] > now or li[i][1] <= now: