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

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

l = 0

r = N + 1

ans = 1

for i in range(M):

    if AB[i][0] < r:



        r = min(r, AB[i][1])

    else:

        ans += 1

        r = AB[i][1]

    l = AB[i][0]

print(ans)
import bisect

N, M, *AB = [int(_) for _ in open(0).read().split()]

AB = sorted(zip(AB[::2], AB[1::2]))

l, r = AB[0]

ans = 1

for a, b in AB[1:]:

    if r <= a:

        l, r = a, b

        ans += 1

    else:

        r = min(r, b)

print(ans)

N, M = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(M)])
l = 0
r = N + 1
ans = 1
for i in range(M):
    if AB[i][0] < r:
        r = min(r, AB[i][1])
    else:
        ans += 1
        r = AB[i][1]
    l = AB[i][0]
print(ans)

import bisect

N, M, *AB = [int(_) for _ in open(0).read().split()]
AB = sorted(zip(AB[::2], AB[1::2]))
l, r = AB[0]
ans = 1
for a, b in AB[1:]:
    if r <= a:
        l, r = a, b
        ans += 1
    else:
        r = min(r, b)
print(ans)

-N, M = [int(_) for _ in input().split()] -AB = sorted([[int(_) for _ in input().split()] for _ in range(M)]) -l = 0 -r = N + 1 +import bisect + +N, M, *AB = [int(_) for _ in open(0).read().split()] +AB = sorted(zip(AB[::2], AB[1::2])) +l, r = AB[0] -for i in range(M): -    if AB[i][0] < r: -        r = min(r, AB[i][1]) +for a, b in AB[1:]: +    if r <= a: +        l, r = a, b +        ans += 1 -        ans += 1 -        r = AB[i][1] -    l = AB[i][0] +        r = min(r, b)