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

info = []

maxa = [0] * (N+1)



for i in range(M):

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

    info.append([a,b])

    if maxa[b] < a:

        maxa[b] = a 



ok = 0

count = 0



for j in range(1,N+1):

    if ok < maxa[j]:

        count += 1

        ok = j-1



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

maxa = [0] * (N+1)



for i in range(M):

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

    if maxa[b] < a:

        maxa[b] = a 



ok = 0

count = 0



for j in range(1,N+1):

    if ok < maxa[j]:

        count += 1

        ok = j-1



print(count)
N, M = list(map(int, input().split()))
info = []
maxa = [0] * (N + 1)
for i in range(M):
    a, b = list(map(int, input().split()))
    info.append([a, b])
    if maxa[b] < a:
        maxa[b] = a
ok = 0
count = 0
for j in range(1, N + 1):
    if ok < maxa[j]:
        count += 1
        ok = j - 1
print(count)

N, M = list(map(int, input().split()))
maxa = [0] * (N + 1)
for i in range(M):
    a, b = list(map(int, input().split()))
    if maxa[b] < a:
        maxa[b] = a
ok = 0
count = 0
for j in range(1, N + 1):
    if ok < maxa[j]:
        count += 1
        ok = j - 1
print(count)

-info = [] -    info.append([a, b])