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

info = []



for i in range(M):

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

    info.append([a,b])



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



ok = 0

count = 0



for i in range(M):

    if info[i][0] > ok:

        count += 1

        ok = info[i][1] - 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()))
info = []
for i in range(M):
    a, b = list(map(int, input().split()))
    info.append([a, b])
info = sorted(info, key=lambda x: x[1])
ok = 0
count = 0
for i in range(M):
    if info[i][0] > ok:
        count += 1
        ok = info[i][1] - 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)

+maxa = [0] * (N + 1) -info = sorted(info, key=lambda x: x[1]) +    if maxa[b] < a: +        maxa[b] = a -for i in range(M): -    if info[i][0] > ok: +for j in range(1, N + 1): +    if ok < maxa[j]: -        ok = info[i][1] - 1 +        ok = j - 1