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

src = [tuple([int(x)-1 for x in input().split()]) for i in range(M)]

src.sort()



ans = 0

minb = N

for a,b in src:

    if a >= minb:

        ans += 1

        minb = b

    else:

        minb = min(minb,b)

if src[-1][0] < minb:

    ans += 1

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

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



ans = 0

cut = -1

src.sort(key=lambda x:x[1])

for a,b in src:

    if a < cut: continue

    cut = b

    ans += 1

print(ans)
N, M = list(map(int, input().split()))
src = [tuple([int(x) - 1 for x in input().split()]) for i in range(M)]
src.sort()
ans = 0
minb = N
for a, b in src:
    if a >= minb:
        ans += 1
        minb = b
    else:
        minb = min(minb, b)
if src[-1][0] < minb:
    ans += 1
print(ans)

N, M = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(M)]
ans = 0
cut = -1
src.sort(key=lambda x: x[1])
for a, b in src:
    if a < cut:
        continue
    cut = b
    ans += 1
print(ans)

-src = [tuple([int(x) - 1 for x in input().split()]) for i in range(M)] -src.sort() +src = [tuple(map(int, input().split())) for i in range(M)] -minb = N +cut = -1 +src.sort(key=lambda x: x[1]) -    if a >= minb: -        ans += 1 -        minb = b -    else: -        minb = min(minb, b) -if src[-1][0] < minb: +    if a < cut: +        continue +    cut = b