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



AB = []

for _ in range(M):

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

    AB.append((a, b))

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



ans = 1

D = AB[0][1]

for i in range(1, M):

    if AB[i][0] >= D:

        ans += 1

        D = AB[i][1]

print(ans)

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



AB = []

for _ in range(M):

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

    AB.append((a, b))

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



ans = 1

D = AB[0][1]

for i in range(1, M):

    if AB[i][0] >= D:

        ans += 1

        D = AB[i][1]

print(ans)

N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    AB.append((a, b))
AB = sorted(AB, key=lambda x: (x[1], x[0]))
ans = 1
D = AB[0][1]
for i in range(1, M):
    if AB[i][0] >= D:
        ans += 1
        D = AB[i][1]
print(ans)

N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    AB.append((a, b))
AB = sorted(AB, key=lambda x: x[1])
ans = 1
D = AB[0][1]
for i in range(1, M):
    if AB[i][0] >= D:
        ans += 1
        D = AB[i][1]
print(ans)

-AB = sorted(AB, key=lambda x: (x[1], x[0])) +AB = sorted(AB, key=lambda x: x[1])