from operator import itemgetter

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

ab = [[0,0] for i in range(M)]

for i in range(M):

    ab[i] = list(map(int, input().split()))



ab = sorted(ab, key=itemgetter(0,1))



re = 1

x, y = ab[0]

for i in range(1, M):

    a, b = ab[i]

    if b <= x or y <= a: # 切ったとこの範囲外だったら

        re += 1

        x, y = a, b

    else:

        x = max(x, 1)

        y = min(y, b)

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



pair = []

for i in range(M):

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

    pair.append([b, a])



# bをキーにして昇順にソートする

pair.sort()



ans = 1

y, x = pair[0]



for i in range(1, M):

    b, a = pair[i]

    if y <= a:

        y = b

        ans += 1



print(ans)
from operator import itemgetter

N, M = list(map(int, input().split()))
ab = [[0, 0] for i in range(M)]
for i in range(M):
    ab[i] = list(map(int, input().split()))
ab = sorted(ab, key=itemgetter(0, 1))
re = 1
x, y = ab[0]
for i in range(1, M):
    a, b = ab[i]
    if b <= x or y <= a:  # 切ったとこの範囲外だったら
        re += 1
        x, y = a, b
    else:
        x = max(x, 1)
        y = min(y, b)
print(re)

N, M = list(map(int, input().split()))
pair = []
for i in range(M):
    a, b = list(map(int, input().split()))
    pair.append([b, a])
# bをキーにして昇順にソートする
pair.sort()
ans = 1
y, x = pair[0]
for i in range(1, M):
    b, a = pair[i]
    if y <= a:
        y = b
        ans += 1
print(ans)

-from operator import itemgetter - -ab = [[0, 0] for i in range(M)] +pair = [] -    ab[i] = list(map(int, input().split())) -ab = sorted(ab, key=itemgetter(0, 1)) -re = 1 -x, y = ab[0] +    a, b = list(map(int, input().split())) +    pair.append([b, a]) +# bをキーにして昇順にソートする +pair.sort() +ans = 1 +y, x = pair[0] -    a, b = ab[i] -    if b <= x or y <= a:  # 切ったとこの範囲外だったら -        re += 1 -        x, y = a, b -    else: -        x = max(x, 1) -        y = min(y, b) -print(re) +    b, a = pair[i] +    if y <= a: +        y = b +        ans += 1 +print(ans)