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



pairs = []



for _ in range(M):

  pairs.append([int(x) for x in input().split()])



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



right_most = 0 # 最後に破壊されている場所（右のindex）



cnt = 0

for a,b in pairs:

  if a < right_most:

    continue

  cnt += 1

  right_most = b



print(cnt)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from operator import itemgetter



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

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

AB = sorted(zip(m,m),key=itemgetter(1))



answer = 0

x = 0

for a,b in AB:

    if a <= x:

        continue

    x=b-1

    answer += 1



print(answer)
N, M = list(map(int, input().split()))
pairs = []
for _ in range(M):
    pairs.append([int(x) for x in input().split()])
pairs.sort(key=lambda x: x[1])
right_most = 0  # 最後に破壊されている場所（右のindex）
cnt = 0
for a, b in pairs:
    if a < right_most:
        continue
    cnt += 1
    right_most = b
print(cnt)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter

N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
AB = sorted(zip(m, m), key=itemgetter(1))
answer = 0
x = 0
for a, b in AB:
    if a <= x:
        continue
    x = b - 1
    answer += 1
print(answer)

-N, M = list(map(int, input().split())) -pairs = [] -for _ in range(M): -    pairs.append([int(x) for x in input().split()]) -pairs.sort(key=lambda x: x[1]) -right_most = 0  # 最後に破壊されている場所（右のindex） -cnt = 0 -for a, b in pairs: -    if a < right_most: +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +from operator import itemgetter + +N, M = list(map(int, readline().split())) +m = list(map(int, read().split())) +AB = sorted(zip(m, m), key=itemgetter(1)) +answer = 0 +x = 0 +for a, b in AB: +    if a <= x: -    cnt += 1 -    right_most = b -print(cnt) +    x = b - 1 +    answer += 1 +print(answer)