# ABC103 D-Islands War



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

ab = []

for i in range(M):

    ab.append(list(map(int, input().split())))

    

ab = sorted(ab, key=lambda x:x[1])

ans = 0

lastremoved = 0



for i, j in enumerate(ab):

    if i == 0:

        ans += 1

        temp = j[1] - 1

    else:

        if j[0] <= temp:

            continue

        else:

            ans += 1

            temp = j[1] - 1

            

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

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

box = sorted(box, key= lambda x: x[1])

rmax = box[0][1]

ans = 1

for i in range(1, M):

    if box[i][0] >= rmax:

        rmax = box[i][1]

        ans += 1

    else:

        continue

print(ans)
# ABC103 D-Islands War
N, M = list(map(int, input().split()))
ab = []
for i in range(M):
    ab.append(list(map(int, input().split())))
ab = sorted(ab, key=lambda x: x[1])
ans = 0
lastremoved = 0
for i, j in enumerate(ab):
    if i == 0:
        ans += 1
        temp = j[1] - 1
    else:
        if j[0] <= temp:
            continue
        else:
            ans += 1
            temp = j[1] - 1
print(ans)

N, M = list(map(int, input().split()))
box = [list(map(int, input().split())) for _ in range(M)]
box = sorted(box, key=lambda x: x[1])
rmax = box[0][1]
ans = 1
for i in range(1, M):
    if box[i][0] >= rmax:
        rmax = box[i][1]
        ans += 1
    else:
        continue
print(ans)

-# ABC103 D-Islands War -ab = [] -for i in range(M): -    ab.append(list(map(int, input().split()))) -ab = sorted(ab, key=lambda x: x[1]) -ans = 0 -lastremoved = 0 -for i, j in enumerate(ab): -    if i == 0: +box = [list(map(int, input().split())) for _ in range(M)] +box = sorted(box, key=lambda x: x[1]) +rmax = box[0][1] +ans = 1 +for i in range(1, M): +    if box[i][0] >= rmax: +        rmax = box[i][1] -        temp = j[1] - 1 -        if j[0] <= temp: -            continue -        else: -            ans += 1 -            temp = j[1] - 1 +        continue