n,m = list(map(int,input().split()))

data = []

for i in range(m):

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

    a -= 1

    b -= 1

    data.append((b,a))

data.sort()

cnt = 0

dis = -1

for i in range(m):

    b,a = data[i]

    if(dis < a):

        cnt += 1

        dis = b - 1

print(cnt)
n,m = list(map(int,input().split()))

data = []

for i in range(m):

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

    a -= 1

    b -= 1

    data.append((a,b))

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

cnt = 0

dis = -1

for i in range(m):

    a,b = data[i]

    if(dis < a):

        cnt += 1

        dis = b - 1

print(cnt)
n, m = list(map(int, input().split()))
data = []
for i in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    data.append((b, a))
data.sort()
cnt = 0
dis = -1
for i in range(m):
    b, a = data[i]
    if dis < a:
        cnt += 1
        dis = b - 1
print(cnt)

n, m = list(map(int, input().split()))
data = []
for i in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    data.append((a, b))
data = sorted(data, key=lambda x: x[1])
cnt = 0
dis = -1
for i in range(m):
    a, b = data[i]
    if dis < a:
        cnt += 1
        dis = b - 1
print(cnt)

-    data.append((b, a)) -data.sort() +    data.append((a, b)) +data = sorted(data, key=lambda x: x[1]) -    b, a = data[i] +    a, b = data[i]