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

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

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



res = 0

i = 1

for m in range(M):

    if req[m][0] >= i:

        i = req[m][1]

        res += 1



print(res)

import sys





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

bridge = [[] for _ in range(N)]

for x in sys.stdin.readlines():

    a, b = list(map(int, x.split()))

    a -= 1; b -= 1

    bridge[a].append(b)



ans = 0

near = N

for i in range(N):

    if near == i:

        ans += 1

        near = N

    for e in bridge[i]:

        near = min(near, e)



print(ans)

N, M = list(map(int, input().split()))
req = [tuple(map(int, input().split())) for _ in range(M)]
req.sort(key=lambda x: x[1])
res = 0
i = 1
for m in range(M):
    if req[m][0] >= i:
        i = req[m][1]
        res += 1
print(res)

import sys

N, M = list(map(int, input().split()))
bridge = [[] for _ in range(N)]
for x in sys.stdin.readlines():
    a, b = list(map(int, x.split()))
    a -= 1
    b -= 1
    bridge[a].append(b)
ans = 0
near = N
for i in range(N):
    if near == i:
        ans += 1
        near = N
    for e in bridge[i]:
        near = min(near, e)
print(ans)

+import sys + -req = [tuple(map(int, input().split())) for _ in range(M)] -req.sort(key=lambda x: x[1]) -res = 0 -i = 1 -for m in range(M): -    if req[m][0] >= i: -        i = req[m][1] -        res += 1 -print(res) +bridge = [[] for _ in range(N)] +for x in sys.stdin.readlines(): +    a, b = list(map(int, x.split())) +    a -= 1 +    b -= 1 +    bridge[a].append(b) +ans = 0 +near = N +for i in range(N): +    if near == i: +        ans += 1 +        near = N +    for e in bridge[i]: +        near = min(near, e) +print(ans)