import heapq



N = int(eval(input()))



red = []

for i in range(N):

    x,y = list(map(int, input().split()))

    heapq.heappush(red, (-y, x))



blue = []

for i in range(N):

    x,y = list(map(int, input().split()))

    heapq.heappush(blue, (x,y))



ans = 0

for i in range(N):

    tmp = []

    bx,by = heapq.heappop(blue)

    flag = True

    while flag:

        mry, rx = heapq.heappop(red)

        if bx > rx and by > -mry:

            ans += 1

            flag = False

            if len(tmp) > 0:

                for mry,rx in tmp:

                    heapq.heappush(red, (mry, rx))

        else:

            tmp.append((mry, rx))



        if len(red) == 0:

            if len(tmp) > 0:

                for mry,rx in tmp:

                    heapq.heappush(red, (mry, rx))

            break

            

print(ans)







N = int(eval(input()))



r = []

for _ in range(N):

    x,y = list(map(int, input().split()))

    r.append((-y,x))



b = []

for _ in range(N):

    x,y = list(map(int, input().split()))

    b.append((x,y))



r.sort()

b.sort()



ans = 0

for my,x in r:

    for j in range(len(b)):

        if  -my < b[j][1] and x < b[j][0]:

            ans += 1

            b.pop(j)

            break



print(ans)

import heapq

N = int(eval(input()))
red = []
for i in range(N):
    x, y = list(map(int, input().split()))
    heapq.heappush(red, (-y, x))
blue = []
for i in range(N):
    x, y = list(map(int, input().split()))
    heapq.heappush(blue, (x, y))
ans = 0
for i in range(N):
    tmp = []
    bx, by = heapq.heappop(blue)
    flag = True
    while flag:
        mry, rx = heapq.heappop(red)
        if bx > rx and by > -mry:
            ans += 1
            flag = False
            if len(tmp) > 0:
                for mry, rx in tmp:
                    heapq.heappush(red, (mry, rx))
        else:
            tmp.append((mry, rx))
        if len(red) == 0:
            if len(tmp) > 0:
                for mry, rx in tmp:
                    heapq.heappush(red, (mry, rx))
            break
print(ans)

N = int(eval(input()))
r = []
for _ in range(N):
    x, y = list(map(int, input().split()))
    r.append((-y, x))
b = []
for _ in range(N):
    x, y = list(map(int, input().split()))
    b.append((x, y))
r.sort()
b.sort()
ans = 0
for my, x in r:
    for j in range(len(b)):
        if -my < b[j][1] and x < b[j][0]:
            ans += 1
            b.pop(j)
            break
print(ans)

-import heapq - -red = [] -for i in range(N): +r = [] +for _ in range(N): -    heapq.heappush(red, (-y, x)) -blue = [] -for i in range(N): +    r.append((-y, x)) +b = [] +for _ in range(N): -    heapq.heappush(blue, (x, y)) +    b.append((x, y)) +r.sort() +b.sort() -for i in range(N): -    tmp = [] -    bx, by = heapq.heappop(blue) -    flag = True -    while flag: -        mry, rx = heapq.heappop(red) -        if bx > rx and by > -mry: +for my, x in r: +    for j in range(len(b)): +        if -my < b[j][1] and x < b[j][0]: -            flag = False -            if len(tmp) > 0: -                for mry, rx in tmp: -                    heapq.heappush(red, (mry, rx)) -        else: -            tmp.append((mry, rx)) -        if len(red) == 0: -            if len(tmp) > 0: -                for mry, rx in tmp: -                    heapq.heappush(red, (mry, rx)) +            b.pop(j)