N, M = [int(str) for str in input().strip().split()]

AB = [[int(str) for str in input().strip().split()] for _ in range(M)]



B_A = [[] for i in range(N + 1)]

for ab in AB:

    B_A[ab[1]].append(ab[0])

for b_a in B_A:

    b_a.sort()





right = 0

ans = 0

for i in range(N + 1):

    if len(B_A[i]):

        if B_A[i][-1] > right:

            ans += 1

            right = i - 1



print(ans)
#!/usr/bin/env python3

N, M = [int(str) for str in input().strip().split()]

ab = [[int(str) for str in input().strip().split()] for _ in range(M)]





def solve():

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

    ans = 0

    broken = 0

    for a, b in ab:

        if a < broken:

            continue

        broken = b

        ans += 1

    print(ans)



solve()

N, M = [int(str) for str in input().strip().split()]
AB = [[int(str) for str in input().strip().split()] for _ in range(M)]
B_A = [[] for i in range(N + 1)]
for ab in AB:
    B_A[ab[1]].append(ab[0])
for b_a in B_A:
    b_a.sort()
right = 0
ans = 0
for i in range(N + 1):
    if len(B_A[i]):
        if B_A[i][-1] > right:
            ans += 1
            right = i - 1
print(ans)

#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
ab = [[int(str) for str in input().strip().split()] for _ in range(M)]


def solve():
    ab.sort(key=lambda x: x[1])
    ans = 0
    broken = 0
    for a, b in ab:
        if a < broken:
            continue
        broken = b
        ans += 1
    print(ans)


solve()

+#!/usr/bin/env python3 -AB = [[int(str) for str in input().strip().split()] for _ in range(M)] -B_A = [[] for i in range(N + 1)] -for ab in AB: -    B_A[ab[1]].append(ab[0]) -for b_a in B_A: -    b_a.sort() -right = 0 -ans = 0 -for i in range(N + 1): -    if len(B_A[i]): -        if B_A[i][-1] > right: -            ans += 1 -            right = i - 1 -print(ans) +ab = [[int(str) for str in input().strip().split()] for _ in range(M)] + + +def solve(): +    ab.sort(key=lambda x: x[1]) +    ans = 0 +    broken = 0 +    for a, b in ab: +        if a < broken: +            continue +        broken = b +        ans += 1 +    print(ans) + + +solve()