islands, requests = list(map(int, input().split(" ")))

req = []

for r in range(requests):

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

    req.append([a, b])

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

answer = 1

temp_end = req[0][1]

for r in req:

    if r[0] >= temp_end:

        temp_end = r[1]

        answer += 1

print(answer)
length, req = list(map(int, input().split(" ")))

target = []

for i in range(req):

    s, e = list(map(int, input().split(" ")))

    target.append([s, e])

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

answer = 0

before_e = -1

for s, e in target:

    # print(before_e, s, e)

    if s < before_e:

        answer += 1

    else:

        before_e = e

print((req - answer))
islands, requests = list(map(int, input().split(" ")))
req = []
for r in range(requests):
    a, b = list(map(int, input().split(" ")))
    req.append([a, b])
req = sorted(req, key=lambda x: x[1])
answer = 1
temp_end = req[0][1]
for r in req:
    if r[0] >= temp_end:
        temp_end = r[1]
        answer += 1
print(answer)

length, req = list(map(int, input().split(" ")))
target = []
for i in range(req):
    s, e = list(map(int, input().split(" ")))
    target.append([s, e])
target.sort(key=lambda x: x[1])
answer = 0
before_e = -1
for s, e in target:
    # print(before_e, s, e)
    if s < before_e:
        answer += 1
    else:
        before_e = e
print((req - answer))

-islands, requests = list(map(int, input().split(" "))) -req = [] -for r in range(requests): -    a, b = list(map(int, input().split(" "))) -    req.append([a, b]) -req = sorted(req, key=lambda x: x[1]) -answer = 1 -temp_end = req[0][1] -for r in req: -    if r[0] >= temp_end: -        temp_end = r[1] +length, req = list(map(int, input().split(" "))) +target = [] +for i in range(req): +    s, e = list(map(int, input().split(" "))) +    target.append([s, e]) +target.sort(key=lambda x: x[1]) +answer = 0 +before_e = -1 +for s, e in target: +    # print(before_e, s, e) +    if s < before_e: -print(answer) +    else: +        before_e = e +print((req - answer))