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

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



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

count = 0

x = 0

for a in A:

    if a[0] > x:

        x = a[1] - 1

        count += 1

        

        

print(count)

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

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





ans = 0

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

last = 0

for i, v in enumerate(AB):

    if last < v[0]:

        last = v[1]-1

        ans += 1





print(ans)
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]
A = sorted(A, key=lambda x: x[1])
count = 0
x = 0
for a in A:
    if a[0] > x:
        x = a[1] - 1
        count += 1
print(count)

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
ans = 0
AB = sorted(AB, key=lambda x: x[1])
last = 0
for i, v in enumerate(AB):
    if last < v[0]:
        last = v[1] - 1
        ans += 1
print(ans)

-A = [list(map(int, input().split())) for i in range(M)] -A = sorted(A, key=lambda x: x[1]) -count = 0 -x = 0 -for a in A: -    if a[0] > x: -        x = a[1] - 1 -        count += 1 -print(count) +AB = [list(map(int, input().split())) for i in range(M)] +ans = 0 +AB = sorted(AB, key=lambda x: x[1]) +last = 0 +for i, v in enumerate(AB): +    if last < v[0]: +        last = v[1] - 1 +        ans += 1 +print(ans)