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

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

L.sort()

ans = 0

l,r = 0,0

for a,b in L:

    l = a

    if r <= a:

        ans += 1

        r = b

    else:

        r = min(r,b)

print(ans)

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

L = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:x[1])

p,res = 0,0

for a,b in L:

    if a > p:

        p = b-1

        res += 1

print(res)

N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(M)]
L.sort()
ans = 0
l, r = 0, 0
for a, b in L:
    l = a
    if r <= a:
        ans += 1
        r = b
    else:
        r = min(r, b)
print(ans)

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

-L = [list(map(int, input().split())) for i in range(M)] -L.sort() -ans = 0 -l, r = 0, 0 +L = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1]) +p, res = 0, 0 -    l = a -    if r <= a: -        ans += 1 -        r = b -    else: -        r = min(r, b) -print(ans) +    if a > p: +        p = b - 1 +        res += 1 +print(res)