import sys



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

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

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



ans = 0

last = -1

for a, b in ab:

    if a < last:

        continue

    else:

        ans += 1

        last = b



print(ans)
import sys



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

ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]

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



ans = 0

last = -1

for a, b in ab:

    if a < last:

        continue

    else:

        ans += 1

        last = b



print(ans)
import sys

N, M = list(map(int, input().split()))
ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b
print(ans)

import sys

N, M = list(map(int, input().split()))
ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
ab.sort(key=lambda x: x[1])
ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b
print(ans)

-ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] +ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]