n, m = [int(i) for i in input().split()]

A = [[int(i) for i in input().split()] for j in range(m)]



A.sort(key=lambda a:a[1])

ans = 0

i = 0



while i < m:

    b = A[i][1]

    ans += 1

    i += 1

    while i < m:

        if A[i][0] >= b:

            break

        i += 1



print(ans)
n, m = [int(i) for i in input().split()]

A = [[int(i) for i in input().split()] for j in range(m)]



A.sort(key=lambda a:a[1])

ans = 0

last = 0



for a, b in A:

    if a >= last:

        ans += 1

        last = b



print(ans)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.sort(key=lambda a: a[1])
ans = 0
i = 0
while i < m:
    b = A[i][1]
    ans += 1
    i += 1
    while i < m:
        if A[i][0] >= b:
            break
        i += 1
print(ans)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.sort(key=lambda a: a[1])
ans = 0
last = 0
for a, b in A:
    if a >= last:
        ans += 1
        last = b
print(ans)

-i = 0 -while i < m: -    b = A[i][1] -    ans += 1 -    i += 1 -    while i < m: -        if A[i][0] >= b: -            break -        i += 1 +last = 0 +for a, b in A: +    if a >= last: +        ans += 1 +        last = b