from bisect import bisect_left



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

ab = [0]*M

for i in range(M):

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

ab.sort()





used = [False]*M

count = 0

for i in range(M):

    if used[i]:

        continue

    head, tail = ab[i]

    used[i] = True

    j = i+1

    while j < M:

        h, t = ab[j]

        if tail <= h:

            break

        tail = min(tail, t)

        used[j] = True

        j += 1

    count += 1

print(count)

from bisect import bisect_left



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

ab = [0]*M

for i in range(M):

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

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



cutted = [-1]

for i in range(M):

    a, b = ab[i]

    if a <= cutted[-1]:

        continue

    cutted.append(b-1)

print((len(cutted)-1))

from bisect import bisect_left

N, M = list(map(int, input().split()))
ab = [0] * M
for i in range(M):
    ab[i] = tuple(map(int, input().split()))
ab.sort()
used = [False] * M
count = 0
for i in range(M):
    if used[i]:
        continue
    head, tail = ab[i]
    used[i] = True
    j = i + 1
    while j < M:
        h, t = ab[j]
        if tail <= h:
            break
        tail = min(tail, t)
        used[j] = True
        j += 1
    count += 1
print(count)

from bisect import bisect_left

N, M = list(map(int, input().split()))
ab = [0] * M
for i in range(M):
    ab[i] = tuple(map(int, input().split()))
ab.sort(key=lambda x: x[1])
cutted = [-1]
for i in range(M):
    a, b = ab[i]
    if a <= cutted[-1]:
        continue
    cutted.append(b - 1)
print((len(cutted) - 1))

-ab.sort() -used = [False] * M -count = 0 +ab.sort(key=lambda x: x[1]) +cutted = [-1] -    if used[i]: +    a, b = ab[i] +    if a <= cutted[-1]: -    head, tail = ab[i] -    used[i] = True -    j = i + 1 -    while j < M: -        h, t = ab[j] -        if tail <= h: -            break -        tail = min(tail, t) -        used[j] = True -        j += 1 -    count += 1 -print(count) +    cutted.append(b - 1) +print((len(cutted) - 1))