n = int(input())
arr = []
for i in range(n):
    arr.append(tuple(map(int, input().split(' '))))
arr = sorted(arr, key=lambda x: x[0])
arr = sorted(arr, key=lambda x: x[1])
last = 0
count = 0
for i in arr:
    if last <= i[0]:
        count += 1
        last = i[1]
print(count)

b6dc38e288241d1db11ae27a7e529f41f7ad6ad0
<mask token>

<mask token>
for i in range(n):
    arr.append(tuple(map(int, input().split(' '))))
<mask token>
for i in arr:
    if last <= i[0]:
        count += 1
        last = i[1]
print(count)

n = int(input())
arr = []
for i in range(n):
    arr.append(tuple(map(int, input().split(' '))))
arr = sorted(arr, key=lambda x: x[0])
arr = sorted(arr, key=lambda x: x[1])
last = 0
count = 0
for i in arr:
    if last <= i[0]:
        count += 1
        last = i[1]
print(count)
