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

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

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



rbs = []

for a, b in bs:

    if not rbs or a > rbs[-1]:

        rbs.append(b - 1)

ans = len(rbs)

print(ans)
import sys

sin = sys.stdin.readline

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

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

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



rbs = []

for a, b in bs:

    if not rbs or a > rbs[-1]:

        rbs.append(b - 1)

ans = len(rbs)

print(ans)
N, M = list(map(int, input().split()))
bs = [tuple(map(int, input().split())) for _ in range(M)]
bs.sort(key=lambda x: x[1])
rbs = []
for a, b in bs:
    if not rbs or a > rbs[-1]:
        rbs.append(b - 1)
ans = len(rbs)
print(ans)

import sys

sin = sys.stdin.readline
N, M = list(map(int, sin().split()))
bs = [tuple(map(int, sin().split())) for _ in range(M)]
bs.sort(key=lambda x: x[1])
rbs = []
for a, b in bs:
    if not rbs or a > rbs[-1]:
        rbs.append(b - 1)
ans = len(rbs)
print(ans)

-N, M = list(map(int, input().split())) -bs = [tuple(map(int, input().split())) for _ in range(M)] +import sys + +sin = sys.stdin.readline +N, M = list(map(int, sin().split())) +bs = [tuple(map(int, sin().split())) for _ in range(M)]