On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.
At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

-----Constraints-----
 - All input values are integers.
 - 1 \leq N \leq 100
 - 0 \leq a_i, b_i, c_i, d_i < 2N
 - a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.
 - b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

-----Output-----
Print the maximum number of friendly pairs.

-----Sample Input-----
3
2 0
3 1
1 3
4 2
0 4
5 5

-----Sample Output-----
2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Difficulty: EASY

Solutions:
n = int(input())
f = lambda x: sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda k: k[x])
(qr, qb) = (f(1)[::-1], f(0))
a = 0
for (c, d) in qb:
	for i in range(n - a):
		if c > qr[i][0] and d > qr[i][1]:
			qr.pop(i)
			a += 1
			break
print(a)


N = int(input())
ab = [tuple(map(int, input().split())) for _ in range(N)]
cd = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort(key=lambda xy: xy[1], reverse=True)
cd.sort()
ans = 0
for (c, d) in cd:
	for (index, (a, b)) in enumerate(ab):
		if a < c and b < d:
			ab[index] = (201, 201)
			ans += 1
			break
print(ans)


N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
R.sort(key=lambda x: -x[1])
B.sort(key=lambda x: x[0])
idx = 0
ans = 0
for (xr, yr) in R:
	for (xb, yb) in B:
		if xr < xb and yr < yb:
			ans += 1
			B.remove([xb, yb])
			break
print(ans)


N = int(input())
Red = sorted([tuple(map(int, input().split())) for _ in range(N)])
Blue = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans = 0
for (bx, by) in Blue:
	C = [(y, x) for (x, y) in Red if x < bx and y < by]
	if len(C) == 0:
		continue
	ans += 1
	C.sort(reverse=True)
	Red.remove((C[0][1], C[0][0]))
print(ans)


N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
blue = sorted(blue, key=lambda x: x[0])
used = []
for i in range(N):
	(c, d) = blue[i]
	(m, tmp) = (-1, -1)
	for j in range(N):
		if j in used:
			continue
		(a, b) = red[j]
		if a < c and b < d:
			if b > m:
				m = b
				tmp = j
	if tmp != -1:
		used.append(tmp)
print(len(used))


n = int(input())
reds = list()
blues = list()
cnt = 0
for i in range(n):
	reds.append(list(map(int, input().split())))
for i in range(n):
	blues.append(list(map(int, input().split())))
blues = sorted(blues, key=lambda x: x[0])
reds = sorted(reds, key=lambda x: x[1], reverse=True)
for blue in blues:
	for red in reds:
		if red[0] < blue[0] and red[1] < blue[1]:
			cnt += 1
			red[0] = 201
			break
print(cnt)


N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
ans = 0
red = sorted(red, key=lambda x: -1 * x[1])
blue = sorted(blue)
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			red.remove(r)
			break
print(ans)


n = int(input())
AB = sorted([[int(i) for i in input().split()] for i in range(n)], reverse=True)
CD = sorted([[int(i) for i in input().split()] for i in range(n)], key=lambda x: x[1])
cnt = 0
for (a, b) in AB:
	for cd in CD:
		if a < cd[0] and b < cd[1]:
			cnt += 1
			CD.remove(cd)
			break
print(n - len(CD))


N = int(input())
ab = []
cd = []
for i in range(N):
	ab.append(list(map(int, input().split())))
for i in range(N):
	cd.append(list(map(int, input().split())))
ab.sort(key=lambda x: x[0], reverse=True)
cd.sort(key=lambda x: x[1])
ans = 0
for (a, b) in ab:
	for (c, d) in cd:
		if a < c and b < d:
			ans += 1
			cd.remove([c, d])
			break
print(ans)


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(n)]
b.sort()
a = sorted(a, key=lambda x: -x[1])
d = 0
for i in range(n):
	for j in range(len(a)):
		if b[i][0] > a[j][0] and b[i][1] > a[j][1]:
			d += 1
			del a[j]
			break
print(d)


n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort(key=lambda x: -x[1])
blue.sort()
count = 0
for (xb, yb) in blue:
	for i in range(n):
		if xb > red[i][0] and yb > red[i][1]:
			red[i] = (201, 201)
			count += 1
			break
print(count)


import sys
sys.setrecursionlimit(10 ** 8)

def ii():
	return int(sys.stdin.readline())

def mi():
	return map(int, sys.stdin.readline().split())

def li():
	return list(map(int, sys.stdin.readline().split()))

def li2(N):
	return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def dp2(ini, i, j):
	return [[ini] * i for _ in range(j)]
N = ii()
A = li2(N)
B = li2(N)
A = sorted(A, key=lambda x: x[1])
B = sorted(B, key=lambda x: x[0])
flag = [0] * N
for i in range(N):
	ind = -1
	for j in range(N):
		if A[j][1] < B[i][1]:
			ind = j
	while ind >= 0:
		if not flag[ind] and A[ind][0] < B[i][0]:
			flag[ind] = 1
			break
		ind -= 1
print(sum(flag))


N = int(input())
s = []
t = []
for i in range(N):
	(a, b) = map(int, input().split())
	t += [(a, b)]
for j in range(N):
	(c, d) = map(int, input().split())
	s += [(c, d)]
s = sorted(s)
t = sorted(t)
for k in range(N):
	(x, y) = (-1, -1)
	for ii in range(len(t)):
		if s[k][0] > t[ii][0] and s[k][1] > t[ii][1] and (y < t[ii][1]):
			(x, y) = t[ii]
	if (x, y) in t:
		t.remove((x, y))
print(N - len(t))


N = int(input())
rps = [tuple(map(int, input().split())) for _ in range(N)]
bps = [tuple(map(int, input().split())) for _ in range(N)]
bps.sort()
rps.sort(key=lambda x: x[1], reverse=True)
count = 0
for bp in bps:
	for (i, rp) in enumerate(rps):
		if rp[0] < bp[0] and rp[1] < bp[1]:
			count += 1
			rps.pop(i)
			break
print(count)


n = int(input())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(n)]
AB = sorted(AB, reverse=True, key=lambda x: x[1])
CD = sorted(CD)
for i in range(n):
	for j in range(len(CD)):
		if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
			CD.pop(j)
			break
print(n - len(CD))


n = int(input())
r = [list(map(int, input().split())) for _ in range(n)]
b = sorted([list(map(int, input().split())) for _ in range(n)])
p = 0
for i in range(n):
	c = []
	for j in range(len(r)):
		if r[j][0] < b[i][0] and r[j][1] < b[i][1]:
			c.append(r[j][::-1])
	if len(c) == 0:
		continue
	c.sort(reverse=1)
	del r[r.index(c[0][::-1])]
	p += 1
print(p)


N = int(input())
R = [list(map(int, input().split())) for k in range(N)]
B = [list(map(int, input().split())) for k in range(N)]
R = sorted(R, key=lambda x: -1 * x[1])
B = sorted(B)
ans = 0
for b in B:
	for r in R:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			R.remove(r)
			break
print(ans)


N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
R.sort(key=lambda x: x[1], reverse=True)
B.sort()
ANS = 0
checked = [0] * N
for (x1, y1) in R:
	for i in range(N):
		(x2, y2) = B[i]
		if x1 < x2 and y1 < y2 and (checked[i] == 0):
			ANS += 1
			checked[i] = 1
			break
print(ANS)


n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], x[0]))
cd.sort(key=lambda x: (x[0], x[1]))
s = [0] * n
for i in range(n):
	for j in range(n):
		if s[j] == 0 and ab[j][0] < cd[i][0] and (ab[j][1] < cd[i][1]):
			s[j] = 1
			break
print(sum(s))


n = int(input())
ab = sorted([[int(a) for a in input().split()] for _ in range(n)], reverse=True)
cd = sorted([[int(a) for a in input().split()] for _ in range(n)], key=lambda x: x[1])
count = 0
for c in cd:
	for a in ab:
		if a[0] < c[0] and a[1] < c[1]:
			count += 1
			ab.remove(a)
			break
print(count)


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
g = [[0 for _ in range(2 * n + 2)] for _ in range(2 * n + 2)]
for (i, (a, b)) in enumerate(ab):
	fr = i + 2
	g[0][fr] = 1
	for (j, (c, d)) in enumerate(cd):
		to = n + j + 2
		g[to][1] = 1
		if a < c and b < d:
			g[fr][to] = 1
used = [False for _ in range(2 * n + 2)]
path = []
goal = 1
flow = [[0 for _ in range(2 * n + 2)] for _ in range(2 * n + 2)]

def bfs(v):
	used[v] = True
	for next in range(2 * n + 2):
		if g[v][next] == 0 or used[next]:
			pass
		elif next == goal:
			path.append(v)
			return True
		elif bfs(next):
			path.append(v)
			return True
	return False
ans = 0
while bfs(0):
	path.reverse()
	path.append(1)
	for i in range(len(path) - 1):
		g[path[i]][path[i + 1]] -= 1
		g[path[i + 1]][path[i]] += 1
	used = [False for _ in range(2 * n + 2)]
	path = []
	ans += 1
print(ans)


import networkx as nx
N = int(input())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
CDs = [tuple(map(int, input().split())) for _ in range(N)]
DG = nx.DiGraph()
DG.add_nodes_from(list(range(2 * N + 3)))
for i in range(N):
	for j in range(N):
		if ABs[i][0] < CDs[j][0] and ABs[i][1] < CDs[j][1]:
			DG.add_edge(i, j + N, capacity=1)
DG.add_edges_from([(2 * N + 1, i, {'capacity': 1}) for i in range(N)])
DG.add_edges_from([(i, 2 * N + 2, {'capacity': 1}) for i in range(N, 2 * N)])
print(nx.maximum_flow_value(DG, 2 * N + 1, 2 * N + 2))


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
x = []
for (i, j) in a:
	x.append((i, j, 1))
for (i, j) in b:
	x.append((i, j, 2))
x.sort()
for i in range(2 * n):
	x[i] = (x[i][1], x[i][2])
ans = 0
while len(x):
	maxindex = 0
	maxvalue = -1
	flag = 0
	for i in range(len(x)):
		if x[i][0] > maxvalue and x[i][1] == 1:
			flag = 1
			maxvalue = x[i][0]
			maxindex = i
	if flag == 0:
		break
	flag = 0
	for i in range(maxindex + 1, len(x)):
		if x[i][1] == 2:
			if x[i][0] > maxvalue:
				ans += 1
				x.pop(i)
				x.pop(maxindex)
				flag = 1
				break
	if flag == 0:
		x.pop(maxindex)
print(ans)


n = int(input())
AB = list((list(map(int, input().split())) for _ in range(n)))
CD = list((list(map(int, input().split())) for _ in range(n)))
CD.sort()
AB.sort(key=lambda z: z[1], reverse=True)
dim_b = [[] for _ in range(n)]
for b in range(n):
	for r in range(n):
		if AB[r][0] < CD[b][0] and AB[r][1] < CD[b][1]:
			dim_b[b] += [r]
vis_r = [False] * n
for b in range(n):
	for r in dim_b[b]:
		if not vis_r[r]:
			vis_r[r] = True
			break
print(sum(vis_r))


N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]
RY = sorted(R, key=lambda x: x[1], reverse=True)
BX = sorted(B, key=lambda x: x[0])
ans = 0
for b in BX:
	for (index, r) in enumerate(RY):
		if b[0] > r[0] and b[1] > r[1]:
			ans += 1
			RY.pop(index)
			break
print(ans)


n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
blue = [list(map(int, input().split())) for i in range(n)]
red.sort(key=lambda x: x[1], reverse=True)
blue.sort(key=lambda x: x[0])
c = 0
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			c += 1
			red.remove(r)
			break
print(c)


n = int(input())
ab = [tuple(map(int, input().split())) for i in range(n)]
cd = [tuple(map(int, input().split())) for i in range(n)]
ans = 0
ab = sorted(ab, key=lambda x: x[1], reverse=True)
cd.sort()
for (c, d) in cd:
	for (a, b) in ab:
		if a < c and b < d:
			ans += 1
			ab.remove((a, b))
			break
print(ans)


N = int(input())
(Red, Blue) = ([], [])
for n in range(N):
	Red.append([int(ab) for ab in input().split()])
Red.sort(key=lambda x: x[1], reverse=True)
for n in range(N):
	Blue.append([int(cd) for cd in input().split()])
Blue.sort(key=lambda x: x[0])
pairs = 0
for B in Blue:
	(c, d) = B
	for R in Red:
		(a, b) = R
		if a < c and b < d:
			pairs += 1
			Red.remove(R)
			break
print(pairs)


n = int(input())
r = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(n)]
b.sort(key=lambda x: x[0])
cnt = 0
r_used = [False] * n
for i in range(n):
	(bx, by) = (b[i][0], b[i][1])
	max_y = -1
	idx = -1
	for j in range(n):
		if r[j][0] < bx and r[j][1] < by and (max_y < r[j][1]) and (not r_used[j]):
			idx = j
			max_y = r[j][1]
	if idx >= 0:
		r_used[idx] = True
		cnt += 1
print(cnt)


N = int(input())
R = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0])
B = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0])
U = [0] * N
for (c, d) in B:
	(i, mv, mi) = (0, -1, 0)
	for (a, b) in R:
		if a < c:
			if b < d and U[i] == 0:
				if mv < b:
					(mv, mi) = (b, i)
			i += 1
		else:
			break
	if mv != -1:
		U[mi] = 1
print(sum(U))


n = int(input())
Red = [list(map(int, input().split())) for i in range(n)]
Blue = [list(map(int, input().split())) for i in range(n)]
Red.sort(key=lambda x: x[1], reverse=True)
Blue.sort()
cnt = 0
for b in Blue:
	for r in Red:
		if b[0] > r[0] and b[1] > r[1]:
			cnt += 1
			r[0] = 10 ** 9
			r[1] = 10 ** 9
			break
print(cnt)


n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda xy: xy[1], reverse=True)
cd.sort()
ans = 0
for b in cd:
	for r in ab:
		if r[0] < b[0] and r[1] < b[1]:
			ab.remove(r)
			ans += 1
			break
print(ans)


n = int(input())
r = [[int(i) for i in input().split()] for i in range(n)]
b = [[int(i) for i in input().split()] for i in range(n)]
for i in r:
	(i[0], i[1]) = (i[1], i[0])
(r, b) = (sorted(r)[::-1], sorted(b))
answer = 0
for i in b:
	for j in r:
		if i[0] > j[1] and i[1] > j[0]:
			answer += 1
			r.remove(j)
			break
print(answer)


def abc091_c():
	n = int(input())
	red = []
	blue = []
	for _ in range(n):
		(a, b) = (int(x) for x in input().split())
		red.append((a, b))
	for _ in range(n):
		(c, d) = (int(x) for x in input().split())
		blue.append((c, d))
	blue = sorted(blue, key=lambda x: x[0])
	ans = 0
	r_used = [False] * n
	for (c, d) in blue:
		match = -1
		y_high = -1
		for (i, (a, b)) in enumerate(red):
			if r_used[i]:
				continue
			if not (a < c and b < d):
				continue
			if y_high < b:
				match = i
				y_high = b
		if match != -1:
			ans += 1
			r_used[match] = True
	print(ans)

def __starting_point():
	abc091_c()
__starting_point()


N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
R.sort(key=lambda x: x[1], reverse=True)
B.sort(key=lambda x: x[0], reverse=False)
ans = 0
for b in B:
	for r in R:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			R.remove(r)
			break
print(ans)


n = int(input())
reds = [tuple(map(int, input().split())) for _ in range(n)]
blues = [tuple(map(int, input().split())) for _ in range(n)]
blues.sort(key=lambda x: x[0])
reds.sort(key=lambda x: x[1])
count = 0
for b in blues:
	(bx, by) = b
	for r in reds[::-1]:
		(rx, ry) = r
		if bx > rx and by > ry:
			count += 1
			reds.remove(r)
			break
print(count)


n = int(input())
f = lambda x: sorted([list(map(int, input().split())) for _ in range(n)], key=lambda k: k[x])
(qr, qb) = (f(1)[::-1], f(0))
a = 0
for (c, d) in qb:
	for r in qr:
		if c > r[0] and d > r[1]:
			qr.remove(r)
			a += 1
			break
print(a)


N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
for p in r:
	(p[0], p[1]) = (p[1], p[0])
(r, b) = (sorted(r, reverse=True), sorted(b))
for i in b:
	for j in r:
		if i[0] > j[1] and i[1] > j[0]:
			ans += 1
			r.remove(j)
			break
print(ans)


n = int(input())
r = sorted([list(map(int, input().split())) for i in range(n)])
b = sorted([list(map(int, input().split())) for i in range(n)])
ans = 0
for (bx, by) in b:
	ypoint = -1
	index = -1
	for (num, (rx, ry)) in enumerate(r):
		if bx > rx and by > ry and (ypoint < ry):
			ypoint = ry
			index = num
	if ypoint >= 0:
		ans += 1
		r.pop(index)
print(ans)


N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
B.sort(key=lambda x: x[0])
A.sort(key=lambda x: x[1])
C = [0] * N
cnt = 0
for i in range(N):
	for j in range(N):
		if C[j] == 0 and A[-i - 1][0] < B[j][0] and (A[-i - 1][1] < B[j][1]):
			C[j] = 1
			cnt += 1
			break
print(cnt)


N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
CD = [list(map(int, input().split())) for i in range(N)]
AB.sort()
CD.sort()
ans = 0
for cd in CD:
	li = []
	for ab in AB:
		if ab[0] < cd[0] and ab[1] < cd[1]:
			li.append(ab)
	li.sort(key=lambda x: x[1])
	if len(li) != 0:
		AB.remove(li[-1])
		ans += 1
print(ans)


from heapq import heapify, heappush, heappop
N = int(input())
A = []
for i in range(N):
	A.append(tuple(map(int, input().split())))
A.sort()
B = []
for i in range(N):
	B.append(tuple(map(int, input().split())))
B.sort()
heap = []
heapify(heap)
aindex = count = 0
for b in B:
	while aindex < len(A) and A[aindex][0] < b[0]:
		heappush(heap, -A[aindex][1])
		aindex += 1
	buf = []
	while heap and b[1] <= -heap[0]:
		ay = heappop(heap)
		buf.append(ay)
	if heap and -heap[0] < b[1]:
		count += 1
		heappop(heap)
	for ay_ in buf:
		heappush(heap, ay_)
print(count)


N = int(input())
R = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
B = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
	temp_y = -1
	temp_ind = -1
	for j in range(len(R)):
		if R[j][0] < B[i][0] and R[j][1] < B[i][1] and (R[j][1] > temp_y):
			temp_y = R[j][1]
			temp_ind = j
	if temp_ind != -1:
		cnt += 1
		R.pop(temp_ind)
print(cnt)


n = int(input())
b = [[int(i) for i in input().split()] for j in range(n)]
a = [[int(i) for i in input().split()] for j in range(n)]
a = sorted(a, key=lambda x: x[0])
b = sorted(b, key=lambda x: x[1], reverse=True)
ans = 0
for ai in range(n):
	for bi in range(len(b)):
		if b[bi][0] < a[ai][0] and b[bi][1] < a[ai][1]:
			ans += 1
			del b[bi]
			break
print(ans)


N = int(input())
r = [tuple(map(int, input().split())) for i in range(N)]
b = [tuple(map(int, input().split())) for i in range(N)]
r.sort()
b.sort()
a = 0
for i in b:
	t = (-1, -1)
	for j in r:
		if j[0] > i[0]:
			break
		if t[1] < j[1] < i[1]:
			t = j
	if t != (-1, -1):
		r.remove(t)
		a += 1
print(a)


N = int(input())
R = [[0, 0, 0] for _ in range(N)]
B = [[0, 0, 0] for _ in range(N)]
for i in range(N):
	(R[i][0], R[i][1]) = map(int, input().split())
for i in range(N):
	(B[i][0], B[i][1]) = map(int, input().split())
R.sort(key=lambda x: x[1], reverse=True)
B.sort()
cnt = 0
for b in B:
	for r in R:
		if b[0] > r[0] and b[1] > r[1] and (r[2] == 0):
			cnt += 1
			r[2] = 1
			break
print(cnt)


from collections import defaultdict
from itertools import product
N = int(input())
red_points = [tuple(map(int, input().split(' '))) for _ in range(N)]
blue_points = [tuple(map(int, input().split(' '))) for _ in range(N)]
edges = defaultdict(set)
for (i, j) in product(list(range(N)), repeat=2):
	(a, b) = red_points[i]
	(c, d) = blue_points[j]
	if a < c and b < d:
		edges[i].add(j + N)
		edges[j + N].add(i)
pairs = [-1] * (2 * N)
ans = 0

def dfs(v, seen):
	seen[v] = True
	for u in edges[v]:
		w = pairs[u]
		if w < 0 or (not seen[w] and dfs(w, seen)):
			pairs[v] = u
			pairs[u] = v
			return True
	return False
for v in range(2 * N):
	if pairs[v] < 0:
		seen = [False] * (2 * N)
		if dfs(v, seen):
			ans += 1
print(ans)


N = int(input())
r = []
for _ in range(N):
	(x, y) = map(int, input().split())
	r.append((-y, x))
b = []
for _ in range(N):
	(x, y) = 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)


n = int(input())
ab = []
for _ in range(n):
	ax = list(map(int, input().split()))
	ab.append(ax)
cd = []
for _ in range(n):
	cx = list(map(int, input().split()))
	cd.append(cx)
ans = 0
cd = sorted(cd)
ab = sorted(ab, key=lambda x: x[1], reverse=True)
ans = 0
for c in cd:
	for a in ab:
		if a[0] < c[0] and a[1] < c[1]:
			ans += 1
			ab.remove(a)
			break
print(ans)


n = int(input())
R = sorted([list(map(int, input().split())) for i in range(n)], key=lambda R: -R[1])
B = sorted([list(map(int, input().split())) for i in range(n)])
ans = 0
for (c, d) in B:
	for (a, b) in R:
		if a < c and b < d:
			R.remove([a, b])
			ans += 1
			break
print(ans)


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[1] * -1)
cd = sorted(cd)
ans = 0
for q in cd:
	for p in ab:
		if q[0] > p[0] and q[1] > p[1]:
			ans += 1
			ab.remove(p)
			break
print(ans)


def c_2d_plane_2n_points_bipartite_graph():
	import networkx as nx
	from networkx.algorithms.flow import dinitz
	N = int(input())
	Red_point_pos = [[int(i) for i in input().split()] for j in range(N)]
	Blue_point_pos = [[int(i) for i in input().split()] for j in range(N)]
	graph = nx.DiGraph()
	graph.add_nodes_from(range(2 * N + 2))
	for i in range(N):
		for j in range(N):
			(a, b) = Red_point_pos[i]
			(c, d) = Blue_point_pos[j]
			if a < c and b < d:
				graph.add_edge(i + 1, j + N + 1, capacity=1)
	for i in range(1, N + 1):
		graph.add_edge(0, i, capacity=1)
	for j in range(N + 1, 2 * N + 1):
		graph.add_edge(j, 2 * N + 1, capacity=1)
	return dinitz(graph, 0, 2 * N + 1).graph['flow_value']
print(c_2d_plane_2n_points_bipartite_graph())


n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]
ans = 0
used = [False] * n
A.sort(key=lambda x: x[1], reverse=True)
C.sort()
for (c, d) in C:
	i = 0
	while i < n and (used[i] or A[i][0] >= c or A[i][1] >= d):
		i += 1
	if i >= n:
		continue
	ans += 1
	used[i] = True
print(ans)


n = int(input())
ab = []
for i in range(n):
	ab.append(list(map(int, input().split())))
ab = sorted(ab, key=lambda x: x[1], reverse=True)
cd = []
for i in range(n):
	cd.append(list(map(int, input().split())))
cd = sorted(cd, key=lambda x: x[0])
ans = 0
for i in cd:
	for (ji, j) in enumerate(ab):
		if i[0] > j[0] and i[1] > j[1]:
			ans += 1
			ab.pop(ji)
			break
print(ans, flush=True)


n = int(input())
reds = sorted([list(map(int, input().split())) for i in range(n)], key=lambda reds: -reds[1])
blues = sorted([list(map(int, input().split())) for i in range(n)])
res = 0
for (c, d) in blues:
	for (a, b) in reds:
		if a < c and b < d:
			reds.remove([a, b])
			res += 1
			break
print(res)


n = int(input())
a = []
c = []
for i in range(n):
	a.append([int(i) for i in input().split()])
for i in range(n):
	c.append([int(i) for i in input().split()])
a.sort(key=lambda x: x[1], reverse=True)
c = sorted(c)
count = 0
for (i, (tc, td)) in enumerate(c):
	for (j, (ta, tb)) in enumerate(a):
		if ta < tc and tb < td:
			count += 1
			a.pop(j)
			break
print(count)


N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
y = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for (c, d) in y:
	for (a, b) in x:
		if a < c and b < d:
			x.remove([a, b])
			cnt += 1
			break
print(cnt)


n = int(input())
aka = []
ao = []
for _ in range(n):
	ab = list(map(int, input().split()))
	aka.append(ab)
aka = sorted(aka, key=lambda x: x[1], reverse=True)
for _ in range(n):
	cd = list(map(int, input().split()))
	ao.append(cd)
ao = sorted(ao)
count = 0
for (a, b) in aka:
	for (c, d) in ao:
		if a < c and b < d:
			ao.remove([c, d])
			count += 1
			break
print(count)


N = int(input())
r = [list(map(int, input().split())) for i in range(N)]
b = [list(map(int, input().split())) for i in range(N)]
ans = 0
(r, b) = (sorted(r, key=lambda x: x[1], reverse=True), sorted(b))
for i in b:
	for j in r:
		if i[1] > j[1] and i[0] > j[0]:
			ans += 1
			r.remove(j)
			break
print(ans)


N = int(input())
Red = [[int(T) for T in input().split()] for TN in range(0, N)]
Red.sort(key=lambda X: X[1], reverse=True)
Blue = [[int(T) for T in input().split()] for TN in range(0, N)]
Blue.sort(key=lambda X: X[0])
Count = 0
for TB in range(0, N):
	DelInd = -1
	for TR in range(0, len(Red)):
		if Blue[TB][0] > Red[TR][0] and Blue[TB][1] > Red[TR][1]:
			DelInd = TR
			break
	if DelInd != -1:
		del Red[DelInd]
		Count += 1
print(Count)


def main():
	n = int(input())
	R = [list(map(int, input().split())) for _ in range(n)]
	B = [list(map(int, input().split())) for _ in range(n)]
	R = sorted(R, key=lambda p: p[1], reverse=True)
	B = sorted(B)
	ans = 0
	for (xB, yB) in B:
		for (xR, yR) in R:
			if xR < xB and yR < yB:
				R.remove([xR, yR])
				ans += 1
				break
	print(ans)
main()


N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]
R.sort(key=lambda x: -x[1])
B.sort()
ans = 0
for (c, d) in B:
	for (a, b) in R:
		if a < c and b < d:
			ans += 1
			R.remove([a, b])
			break
print(ans)


import io
import sys
data = int(input())
array = [list(map(int, input().split())) for i in range(data)]
are = [list(map(int, input().split())) for i in range(data)]
array.sort(key=lambda x: x[1], reverse=1)
are.sort()
result = 0
for b in are:
	for r in array:
		if b[1] > r[1] and b[0] > r[0]:
			result += 1
			array.remove(r)
			break
print(result)


N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(N)]
count = 0
ab.sort(key=lambda x: x[1])
ab.reverse()
cd.sort()
for i in range(N):
	for j in range(N):
		if ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
			count += 1
			ab[j] = [200, 200]
			break
print(count)


N = int(input())
red = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: -1 * x[1])
blue = sorted([list(map(int, input().split())) for i in range(N)])
red = sorted(red, key=lambda x: x[1] * -1)
count = 0
for i in red:
	for (n, j) in enumerate(blue):
		if i[0] < j[0] and i[1] < j[1]:
			count += 1
			del blue[n]
			break
print(count)


((n,), *dot) = [[*map(int, i.split())] for i in open(0)]
red = sorted(dot[:n])
blue = sorted(dot[n:])
for (c, d) in blue:
	o = [[a, b] for (a, b) in red if a < c and b < d]
	if o:
		red.remove(max(o, key=lambda x: x[1]))
print(n - len(red))


import copy
n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)], reverse=True)
cd = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
ans = 0
for i in range(n):
	for j in range(len(cd)):
		if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
			ans += 1
			cd.remove(cd[j])
			break
print(ans)


N = int(input())
red = [tuple([int(i) for i in input().split()]) for _ in range(N)]
blue = [tuple([int(i) for i in input().split()]) for _ in range(N)]
red.sort(key=lambda x: x[1], reverse=True)
blue.sort(key=lambda x: x[0])
ans = 0
for b in blue:
	for (i, r) in enumerate(red):
		if b[0] > r[0] and b[1] > r[1]:
			ans += 1
			red.pop(i)
			break
print(ans)


n = int(input())
list_red = [list(map(int, input().split())) for i in range(n)]
list_blue = [list(map(int, input().split())) for i in range(n)]
list_red.sort(key=lambda x: x[1], reverse=True)
list_blue = sorted(list_blue)
ans = 0
for (c, d) in list_blue:
	for (a, b) in list_red:
		if a < c and b < d:
			list_red.remove([a, b])
			ans += 1
			break
print(ans)


import operator
import bisect
n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort(key=operator.itemgetter(0, 1))
blue.sort(key=operator.itemgetter(0, 1))
count = 0
for i in range(n):
	for j in reversed(list(range(len(red)))):
		if not red:
			break
		if red[j][0] < blue[i][0]:
			tmp = red[:j + 1]
			tmp.sort(key=lambda x: x[1], reverse=True)
			for t in tmp:
				if t[1] < blue[i][1]:
					count += 1
					red.pop(red.index(t))
					break
		else:
			continue
		break
print(count)


N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=max, reverse=True)
CD.sort(key=min)
counter = 0
for (a, b) in AB:
	for (c, d) in CD:
		if a < c and b < d:
			CD.remove((c, d))
			counter += 1
			break
print(counter)


N = int(input())
AB = sorted([list(map(int, input().split())) for _ in range(N)])
CD = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
cnt = 0
for (a, b) in AB[::-1]:
	for (i, j) in enumerate(CD):
		(c, d) = j
		if a < c and b < d:
			cnt += 1
			del CD[i]
			break
print(cnt)


def c_2d_plane_2n_points_bipartite_graph():
	import networkx as nx
	from networkx.algorithms.flow import dinitz
	N = int(input())
	(A, B, C, D) = ([], [], [], [])
	for _ in range(N):
		(a, b) = [int(i) for i in input().split()]
		A.append(a)
		B.append(b)
	for _ in range(N):
		(c, d) = [int(i) for i in input().split()]
		C.append(c)
		D.append(d)
	graph = nx.DiGraph()
	graph.add_nodes_from(range(2 * N + 2))
	for i in range(N):
		for j in range(N):
			if A[i] < C[j] and B[i] < D[j]:
				graph.add_edge(i + 1, j + N + 1, capacity=1)
	for i in range(1, N + 1):
		graph.add_edge(0, i, capacity=1)
	for j in range(N + 1, 2 * N + 1):
		graph.add_edge(j, 2 * N + 1, capacity=1)
	return dinitz(graph, 0, 2 * N + 1).graph['flow_value']
print(c_2d_plane_2n_points_bipartite_graph())


from operator import itemgetter
(n, *ABCD) = map(int, open(0).read().split())
AB = sorted([(a, b) for (a, b) in zip(ABCD[:2 * n:2], ABCD[1:2 * n:2])])
CD = sorted([(c, d) for (c, d) in zip(ABCD[2 * n::2], ABCD[2 * n + 1::2])])
for (c, d) in CD:
	t_AB = [(a, b) for (a, b) in AB if a < c and b < d]
	if t_AB:
		t_AB.sort(key=itemgetter(1))
		AB.remove(t_AB[-1])
print(n - len(AB))


n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(n)]
Red = sorted(AB, key=lambda x: x[1], reverse=True)
Blue = sorted(CD, key=lambda x: x[0])
ans = 0
for b in Blue:
	for r in Red:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			Red.remove(r)
			break
print(ans)


N = int(input())
r = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: -1 * x[1])
b = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
for (xb, yb) in b:
	for (xr, yr) in r:
		if xr < xb and yr < yb:
			r.remove([xr, yr])
			ans += 1
			break
print(ans)


n = int(input())
R = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(n)]
B.sort()
ans = 0
for b in B:
	L = [r for r in R if r[0] < b[0] and r[1] < b[1]]
	if len(L) != 0:
		s = L[0]
		for l in L:
			if s[1] < l[1]:
				s = l
		R.remove(s)
		ans += 1
print(ans)


N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(N)]

def sortx(xy):
	return xy[0]

def sorty(xy):
	return -xy[1]
AB.sort(key=sorty)
CD.sort(key=sortx)
count = 0
for cd in CD:
	for ab in AB:
		if ab[0] < cd[0] and ab[1] < cd[1]:
			count += 1
			AB.remove(ab)
			break
print(count)


import networkx as nx
n = int(input())
graph = nx.DiGraph()
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(n)]
start = 10 ** 4
goal = 10 ** 4 + 1
for i in range(n):
	(a, b) = AB[i]
	graph.add_edge(start, i, weight=0, capacity=1)
	for j in range(n):
		(c, d) = CD[j]
		graph.add_edge(200 + j, goal, weight=0, capacity=1)
		if c > a and d > b:
			graph.add_edge(i, 200 + j, weight=0, capacity=1)
ans = nx.maximum_flow(graph, start, goal, capacity='capacity')
print(ans[0])


n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
B = [[int(i) for i in input().split()] for i in range(n)]
A.sort(reverse=True)
B.sort(key=lambda x: x[1])
count = 0
for i in range(n):
	for j in range(len(B)):
		if A[i][0] < B[j][0] and A[i][1] < B[j][1]:
			count += 1
			B.pop(j)
			break
print(count)


N = int(input())
red = []
blue = []
for _ in range(N):
	(a, b) = map(int, input().split())
	red.append((a, b))
for _ in range(N):
	(c, d) = map(int, input().split())
	blue.append((c, d))
blue.sort(key=lambda x: x[0])
for (bx, by) in blue:
	c = None
	for (rx, ry) in red:
		if rx < bx and ry < by:
			if c is None or c[1] < ry:
				c = (rx, ry)
	if c:
		red.remove(c)
print(N - len(red))


n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
red = sorted(red, reverse=True)
blue = [list(map(int, input().split())) for i in range(n)]
blue = sorted(blue, key=lambda x: x[1])
ans = 0
for re in red:
	(a, b) = re
	for (i, bu) in enumerate(blue):
		(c, d) = bu
		if a < c and b < d:
			ans += 1
			blue.pop(i)
			break
print(ans)


N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
R.sort(key=lambda x: (-x[0], -x[1]))
B.sort(key=lambda x: (x[1], x[0]))
ans = 0
for (rx, ry) in R:
	for (bx, by) in B:
		if rx < bx and ry < by:
			ans += 1
			B.remove([bx, by])
			break
print(ans)


N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]
ab.sort(reverse=True)
cd.sort()
p = 0
for c in cd:
	ac = [-1, -1]
	for a in ab:
		if c[0] > a[0] and c[1] > a[1] and (ac[1] < a[1]):
			ac = a
	if ac != [-1, -1]:
		p += 1
		ab.remove(ac)
print(p)


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1], reverse=True)
cd.sort()
ans = 0
for (c, d) in cd:
	for (a, b) in ab:
		if a < c and b < d:
			ans += 1
			ab.remove([a, b])
			break
print(ans)


n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: (x[1], x[0]), reverse=True)
cd = sorted(cd, key=lambda x: (x[0], x[1]))
cnt = 0
i = j = 0
free_ab = [True] * n
while j < n:
	(a, b) = (ab[i][0], ab[i][1])
	(c, d) = (cd[j][0], cd[j][1])
	if a < c and b < d and free_ab[i]:
		cnt += 1
		free_ab[i] = False
		i = 0
		j += 1
		continue
	elif j <= n - 1 and i < n - 1:
		i += 1
	elif j < n - 1 and i == n - 1:
		i = 0
		j += 1
	else:
		break
print(cnt)


N = int(input())
ab = [[int(i) for i in input().split()] for i in range(N)]
cd = [[int(i) for i in input().split()] for i in range(N)]
abm = [0] * N
ans = 0
ab.sort()
cd.sort()
for i in cd:
	temp = -1
	ind = 0
	for (index, j) in enumerate(ab):
		if i[0] > j[0] and i[1] > j[1] > temp and (abm[index] == 0):
			temp = j[1]
			ind = index
	if temp > -1:
		ans += 1
		abm[ind] = 1
print(ans)


N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) + [1] for _ in range(N)]
AB = sorted(ab, key=lambda x: x[1], reverse=True)
CD = sorted(cd, key=lambda x: x[0])
cnt = 0
for i in range(N):
	for j in range(N):
		if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1] and (CD[j][2] == 1):
			cnt += 1
			CD[j][2] -= 1
			break
print(cnt)


n = int(input())
r = sorted([list(map(int, input().split())) for i in range(n)])
b = sorted([list(map(int, input().split())) for i in range(n)])
ans = 0
for (bx, by) in b:
	now_ry = -1
	now_index = -1
	for (key, (rx, ry)) in enumerate(r):
		if bx > rx and by > ry and (ry > now_ry):
			now_ry = ry
			now_index = key
	if now_ry >= 0:
		ans += 1
		r.pop(now_index)
print(ans)


n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort(key=lambda x: x[1], reverse=True)
blue.sort()
chk = [False] * n
for b in blue:
	for (i, r) in enumerate(red):
		if chk[i]:
			continue
		elif r[0] < b[0] and r[1] < b[1]:
			chk[i] = True
			break
print(sum(chk))


N = int(input())
R = [[int(i) for i in input().split()] for i in range(N)]
B = [[int(i) for i in input().split()] for i in range(N)]
for i in R:
	(i[0], i[1]) = (i[1], i[0])
(R, B) = (sorted(R)[::-1], sorted(B))
answer = 0
for i in B:
	for j in R:
		if i[0] > j[1] and i[1] > j[0]:
			answer += 1
			R.remove(j)
			break
print(answer)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
red_s = sorted(red, key=lambda x: x[1], reverse=True)
blue_s = sorted(blue)
pair = 0
for (bx, by) in blue_s:
	for (i, (rx, ry)) in enumerate(red_s):
		if rx < bx and ry < by:
			pair += 1
			red_s.pop(i)
			break
print(pair)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
red.sort(key=lambda x: x[0], reverse=True)
blue.sort(key=lambda x: x[1])
paired = [0] * n
for (a, b) in red:
	for (i, (c, d)) in enumerate(blue):
		if a < c and b < d and (not paired[i]):
			paired[i] = 1
			break
print(sum(paired))


n = int(input())
r = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(n)]
r.sort(key=lambda x: x[1], reverse=True)
b.sort(key=lambda x: x[0])
ans = 0
for (i, bb) in enumerate(b):
	(c, d) = bb
	for (j, rr) in enumerate(r):
		(a, b) = rr
		if c > a and d > b:
			ans += 1
			del r[j]
			break
print(ans)


n = int(input())
a = sorted([list(map(int, input().split())) for _ in [0] * n], key=lambda x: [-x[1], x[0]])
b = sorted([list(map(int, input().split())) for _ in [0] * n], key=lambda x: [x[0], -x[1]])
c = 0
i = j = 0
while j < n:
	i = 0
	while i < len(a):
		if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
			c += 1
			del a[i]
			break
		i += 1
	j += 1
print(c)


N = int(input())
red = [tuple(map(int, input().split())) for _ in range(N)]
blue = [tuple(map(int, input().split())) for _ in range(N)]
blue = sorted(blue, key=lambda x: x[0])
ans = 0
for b in blue:
	candi = [i for i in red if i[0] < b[0] and i[1] < b[1]]
	if candi:
		red.remove(sorted(candi, key=lambda x: x[1], reverse=True)[0])
		ans += 1
print(ans)


N = int(input())
red = [list(map(int, input().split())) for i in range(N)]
red.sort()
blue = [list(map(int, input().split())) for i in range(N)]
blue.sort()
ans = 0
from operator import itemgetter
for i in range(N):
	(x, y) = blue[i]
	l = []
	for j in range(N):
		try:
			if x > red[j][0] and y > red[j][1]:
				l.append(red[j])
		except IndexError:
			break
	try:
		l.sort(key=itemgetter(1), reverse=True)
		red.remove(l[0])
	except IndexError:
		pass
print(N - len(red))


N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)], key=lambda x: x[1], reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
count = 0
for i in range(N):
	for j in range(len(AB)):
		if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
			del AB[j]
			count += 1
			break
print(count)


from operator import itemgetter
N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
R.sort(reverse=True, key=itemgetter(1))
B.sort()
ans = 0
for b in B:
	for r in R:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			R.remove(r)
			break
print(ans)


N = int(input())
ab = sorted([list(map(int, input().split())) for _ in [0] * N], key=lambda x: x[1], reverse=True)
cd = sorted([list(map(int, input().split())) for _ in [0] * N], key=lambda x: x[0])
cnt = 0
for i in range(N):
	for a in ab:
		if a[0] < cd[i][0] and a[1] < cd[i][1]:
			ab.remove(a)
			cnt += 1
			break
print(cnt)


def main():
	n = int(input())
	(R, B) = ([], [])
	for i in range(n):
		R.append(list(map(int, input().split())) + [0, i])
	for _ in range(n):
		B.append(list(map(int, input().split())))
	B.sort(key=lambda x: x[0])
	ans = 0
	for b in B:
		f = list([x for x in R if x[0] < b[0] and x[1] < b[1] and (x[2] == 0)])
		if len(f) != 0:
			f.sort(key=lambda x: x[1], reverse=True)
			p = f[0]
			ans += 1
			R[p[3]][2] = 1
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[0])
cd.sort(key=lambda x: x[0])
ans = 0
i = 0
red_x = []
import bisect
for (c, d) in cd:
	while i < n and ab[i][0] < c:
		bisect.insort_right(red_x, ab[i][1])
		i += 1
	if red_x and red_x[0] < d:
		idx = bisect.bisect_right(red_x, d) - 1
		ans += 1
		red_x.pop(idx)
print(ans)


N = int(input())
AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1], reverse=True)
CD = sorted([list(map(int, input().split())) for _ in range(N)])
ans = 0
for cd in CD:
	for ab in AB:
		if cd[0] > ab[0] and cd[1] > ab[1]:
			ans += 1
			AB.remove(ab)
			break
print(ans)


import sys
input = sys.stdin.readline
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=1, key=lambda x: x[1])
CD.sort()
ans = 0
for (c, d) in CD:
	for (a, b) in AB:
		if a < c and b < d:
			ans += 1
			AB.remove([a, b])
			break
print(ans)


import sys
mod = 10 ** 9 + 7
inf = float('inf')
from math import sqrt, ceil
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP, Decimal
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from collections import deque

class Dinic:

	def __init__(self, N):
		self.N = N
		self.G = [[] for i in range(N)]

	def add_edge(self, fr, to, cap=1):
		forward = [to, cap, None]
		forward[2] = backward = [fr, 0, forward]
		self.G[fr].append(forward)
		self.G[to].append(backward)

	def add_multi_edge(self, v1, v2, cap1, cap2):
		edge1 = [v2, cap1, None]
		edge1[2] = edge2 = [v1, cap2, edge1]
		self.G[v1].append(edge1)
		self.G[v2].append(edge2)

	def bfs(self, s, t):
		self.level = level = [None] * self.N
		deq = deque([s])
		level[s] = 0
		G = self.G
		while deq:
			v = deq.popleft()
			lv = level[v] + 1
			for (w, cap, _) in G[v]:
				if cap and level[w] is None:
					level[w] = lv
					deq.append(w)
		return level[t] is not None

	def dfs(self, v, t, f):
		if v == t:
			return f
		level = self.level
		for e in self.it[v]:
			(w, cap, rev) = e
			if cap and level[v] < level[w]:
				d = self.dfs(w, t, min(f, cap))
				if d:
					e[1] -= d
					rev[1] += d
					return d
		return 0

	def flow(self, s, t):
		flow = 0
		INF = inf
		G = self.G
		while self.bfs(s, t):
			(*self.it,) = map(iter, self.G)
			f = INF
			while f:
				f = self.dfs(s, t, INF)
				flow += f
		return flow
n = int(input())
dinic = Dinic(2 * n + 2)
A = []
B = []
for i in range(n):
	(a, b) = map(int, input().split())
	A.append([a, b])
for i in range(n):
	(a, b) = map(int, input().split())
	B.append([a, b])
for i in range(n):
	dinic.add_edge(2 * n, i, 1)
	dinic.add_edge(i + n, 2 * n + 1, 1)
for i in range(n):
	for j in range(n):
		if A[i][0] < B[j][0] and A[i][1] < B[j][1]:
			dinic.add_edge(i, j + n)
print(dinic.flow(2 * n, 2 * n + 1))


n = int(input())
ba = []
cd = []
for i in range(n):
	(a, b) = map(int, input().split())
	ba.append([b, a])
for j in range(n):
	(c, d) = map(int, input().split())
	cd.append([c, d])
ba.sort(reverse=True)
cd.sort()
ans = 0
for (c, d) in cd:
	for i in range(n):
		(b, a) = ba[i]
		if a < c and b < d:
			ans += 1
			ba[i] = [201, 201]
			break
print(ans)


import sys
INF = 1 << 60
MOD = 10 ** 9 + 7
sys.setrecursionlimit(2147483647)
input = lambda : sys.stdin.readline().rstrip()
import networkx as nx

def resolve():
	n = int(input())
	A = [tuple(map(int, input().split())) for _ in range(n)]
	B = [tuple(map(int, input().split())) for _ in range(n)]
	G = nx.Graph()
	G.add_nodes_from(range(n))
	G.add_nodes_from(range(n, 2 * n))
	for i in range(n):
		(ax, ay) = A[i]
		for j in range(n):
			(bx, by) = B[j]
			if ax < bx and ay < by:
				G.add_edge(i, n + j)
	A = nx.algorithms.bipartite.matching.hopcroft_karp_matching(G, top_nodes=range(n))
	print(len(A) // 2)
resolve()


import sys
from collections import deque
input = sys.stdin.readline

class Dinic:

	def __init__(self, v):
		self.vertice = v
		self.inf = int(1000000000.0)
		self.graph = [[] for i in range(v)]
		self.level = [0] * v
		self.iter = [0] * v

	def add_edge(self, fr, to, cap):
		self.graph[fr].append([to, cap, len(self.graph[to])])
		self.graph[to].append([fr, 0, len(self.graph[fr]) - 1])

	def bfs(self, s):
		self.level = [-1] * self.vertice
		que = deque([])
		self.level[s] = 0
		que.append(s)
		while que:
			v = que.popleft()
			for i in range(len(self.graph[v])):
				e = self.graph[v][i]
				if e[1] > 0 and self.level[e[0]] < 0:
					self.level[e[0]] = self.level[v] + 1
					que.append(e[0])

	def dfs(self, v, t, f):
		if v == t:
			return f
		for i in range(self.iter[v], len(self.graph[v])):
			self.iter[v] = i
			e = self.graph[v][i]
			if e[1] > 0 and self.level[v] < self.level[e[0]]:
				d = self.dfs(e[0], t, min(f, e[1]))
				if d > 0:
					e[1] -= d
					self.graph[e[0]][e[2]][1] += d
					return d
		return 0

	def max_flow(self, s, t):
		flow = 0
		while True:
			self.bfs(s)
			if self.level[t] < 0:
				return flow
			self.iter = [0] * self.vertice
			f = self.dfs(s, t, self.inf)
			while f:
				flow += f
				f = self.dfs(s, t, self.inf)

def main():
	n = int(input())
	red = [list(map(int, input().split())) for _ in range(n)]
	blue = [list(map(int, input().split())) for _ in range(n)]
	flow = Dinic(n * 2 + 2)
	for i in range(n):
		flow.add_edge(0, i + 1, 1)
		flow.add_edge(n + i + 1, 2 * n + 1, 1)
		for j in range(n):
			if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
				flow.add_edge(i + 1, n + j + 1, 1)
	ans = flow.max_flow(0, 2 * n + 1)
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(N)]
ab.sort(key=lambda x: x[1], reverse=True)
cd.sort()
x = 0
for (c, d) in cd:
	for (a, b) in ab:
		if a < c and b < d:
			x += 1
			ab.remove([a, b])
			break
print(x)


N = int(input())
red = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[1], reverse=True)
blue = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
for (b_x, b_y) in blue:
	for (r_x, r_y) in red:
		if b_x > r_x and b_y > r_y:
			red.remove([r_x, r_y])
			ans += 1
			break
print(ans)


n = int(input())
ab = []
cd = []
for i in range(n):
	ab.append(tuple(map(int, input().split())))
for g in range(n):
	cd.append(tuple(map(int, input().split())))
ab.sort(key=lambda x: x[1], reverse=True)
cd.sort()
used = [False] * n
ans = 0
for i in range(n):
	for g in range(n):
		if ab[i][0] < cd[g][0] and ab[i][1] < cd[g][1] and (not used[g]):
			used[g] = True
			ans += 1
			break
print(ans)


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[1] * -1)
cd = sorted(cd)
cnt = 0
for i in range(n):
	for j in range(len(cd)):
		if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
			cnt += 1
			cd.pop(j)
			break
print(cnt)


(N, *I) = map(int, open(0).read().split())
AB = list(zip(*[iter(I[:2 * N])] * 2))
CD = sorted(zip(*[iter(I[2 * N:])] * 2))
for (c, d) in CD:
	ma = max(((a, b) for (a, b) in AB if a < c and b < d), key=lambda x: x[1], default=None)
	if ma:
		AB.remove(ma)
print(N - len(AB))


from operator import itemgetter
N = int(input())
R = [list(map(int, input().split())) for n in range(N)]
B = [list(map(int, input().split())) for n in range(N)]
R.sort(key=itemgetter(1), reverse=True)
B.sort()
ans = 0
for (c, d) in B:
	for (a, b) in R:
		if a < c and b < d:
			ans += 1
			R.remove([a, b])
			break
print(ans)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
red.sort()
blue.sort()
p = 0
for bb in blue:
	lis = [-1, -1]
	for rr in red:
		if rr[0] < bb[0] and rr[1] < bb[1] and (lis[1] < rr[1]):
			lis = rr
	if lis != [-1, -1]:
		red.remove(lis)
		p += 1
print(p)


n = int(input())
AB = list((list(map(int, input().split())) for _ in range(n)))
CD = list((list(map(int, input().split())) for _ in range(n)))
CD.sort()
AB.sort(key=lambda z: z[1], reverse=True)
dim_b = [[] for _ in range(n)]
for b in range(n):
	(bx, by) = CD[b]
	for r in range(n):
		(rx, ry) = AB[r]
		if rx < bx and ry < by:
			dim_b[b] += [r]
vis_r = [False] * n
for b in range(n):
	max_ry = max_r = -1
	for r in dim_b[b]:
		if vis_r[r]:
			continue
		(rx, ry) = AB[r]
		if max_ry < ry:
			max_ry = ry
			max_r = r
	if max_r >= 0:
		vis_r[max_r] = True
print(sum(vis_r))


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1], reverse=True)
cd.sort(key=lambda x: x[0])
ab_bool = [True] * n
cnt = 0
for i in range(n):
	for j in range(n):
		if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1] and ab_bool[j]:
			cnt += 1
			ab_bool[j] = False
			break
print(cnt)


from operator import itemgetter
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
blue = [list(map(int, input().split())) for i in range(n)]
red.sort()
blue.sort(key=itemgetter(1))
ans = 0
for i in range(n):
	(a, b) = red[-i - 1]
	for j in range(len(blue)):
		(c, d) = blue[j]
		if a < c and b < d:
			ans += 1
			blue[j] = [0, 0]
			break
print(ans)


n = int(input())
r = [list(map(int, input().split())) for i in range(n)]
b = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0])
cnt = 0
for bb in b:
	t_r = [-1, -1]
	for rr in r:
		if rr[0] < bb[0] and t_r[1] < rr[1] < bb[1]:
			t_r = rr
	if t_r != [-1, -1]:
		cnt += 1
		r.remove(t_r)
print(cnt)


n = int(input())
aka = []
ao = []
aka = aka + [list(map(int, input().split())) for _ in range(n)]
ao = ao + [list(map(int, input().split())) for _ in range(n)]
aka = sorted(aka, key=lambda x: x[1], reverse=True)
ao = sorted(ao, key=lambda x: x[0])
ans = 0
for i in range(n):
	for j in range(n):
		if ao[i][0] > aka[j][0] and ao[i][1] > aka[j][1]:
			ans += 1
			aka[j][1] = 201
			break
print(ans)


N = int(input())
reds = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
blues = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
ans = 0
for (bx, by) in blues:
	for (rx, ry) in reds:
		if rx < bx and ry < by:
			ans += 1
			reds.remove((rx, ry))
			break
print(ans)


N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x: x[1])
blue.sort(key=lambda x: x[0])
ct = 0
for i in blue:
	for j in reversed(red):
		if i[0] > j[0] and i[1] > j[1]:
			red.remove(j)
			ct += 1
			break
print(ct)


n = int(input())
reds = [list(map(int, input().split())) for i in range(n)]
blues = [list(map(int, input().split())) for i in range(n)]
reds.sort(key=lambda x: x[1], reverse=True)
blues = sorted(blues)
count = 0
for i in reds:
	for j in blues:
		if i[0] < j[0] and i[1] < j[1]:
			count += 1
			blues.remove(j)
			break
print(count)


N = int(input())
AB = [0] * N
for i in range(N):
	AB[i] = list(map(int, input().split()))
AB = sorted(AB)
CD = [0] * N
for i in range(N):
	CD[i] = list(map(int, input().split()))
CD = sorted(CD)
ans = 0
used = [0] * N
for i in range(N):
	(now_x, now_y) = (CD[i][0], CD[i][1])
	max_y = -1
	nn = -1
	for j in range(N):
		if now_x > AB[j][0] and used[j] == 0:
			if now_y > AB[j][1]:
				if max_y < AB[j][1]:
					max_y = AB[j][1]
					nn = j
	if max_y != -1:
		ans += 1
		used[nn] = 1
print(ans)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for (c, d) in sorted(blue, key=lambda x: x[0]):
	for (a, b) in sorted(red, key=lambda x: x[1], reverse=True):
		if a < c and b < d:
			ans += 1
			red.remove([a, b])
			break
print(ans)


import bisect
N = int(input())
R = [tuple(map(int, input().split())) for i in range(N)]
B = [tuple(map(int, input().split())) for i in range(N)]
R.sort()
B.sort()
i = 0
ans = 0
red_y = []
for (b_x, b_y) in B:
	while i < N and R[i][0] < b_x:
		bisect.insort_right(red_y, R[i][1])
		i += 1
	if red_y and red_y[0] < b_y:
		idx = bisect.bisect_right(red_y, b_y) - 1
		ans += 1
		red_y.pop(idx)
print(ans)


from collections import deque
N = int(input())
start = 0
end = 2 * N + 1
R = {}
B = {}
ad_matrix = [[0] * (2 * N + 2) for i in range(2 * N + 2)]
ad_dict = {}
ad_dict[start] = []
ad_dict[end] = []
for n in range(N):
	R[n + 1] = list(map(int, input().split()))
	ad_dict[n + 1] = []
for n in range(N):
	B[N + n + 1] = list(map(int, input().split()))
	ad_dict[N + n + 1] = []
for r_ in R.keys():
	ad_dict[start].append(r_)
	ad_dict[r_].append(start)
for b_ in B.keys():
	ad_dict[end].append(b_)
	ad_dict[b_].append(end)
for r_ in R.keys():
	ad_matrix[start][r_] = 1
	r = R[r_]
	for b_ in B.keys():
		ad_matrix[b_][end] = 1
		b = B[b_]
		if r[0] < b[0] and r[1] < b[1]:
			ad_matrix[r_][b_] = 1
			ad_dict[r_].append(b_)
ans = 0
while True:
	start = 0
	end = 2 * N + 1
	color = {}
	for n in range(end + 1):
		color[n] = -1
	visit = deque([start])
	color[start] = 0
	while visit:
		start = visit[-1]
		for v in ad_dict[start]:
			if color[v] == -1:
				visit.append(v)
				color[v] = 0
				break
		else:
			visit.pop()
			color[start] = 1
		if color[end] == 0:
			visit = list(visit)
			flow = 10 ** 10
			for (d1, d2) in zip(visit[:-1], visit[1:]):
				flow = min(flow, ad_matrix[d1][d2])
			for (d1, d2) in zip(visit[:-1], visit[1:]):
				ad_matrix[d1][d2] -= flow
				ad_matrix[d2][d1] += flow
				if ad_matrix[d1][d2] <= 0:
					ad_dict[d1].remove(d2)
					ad_dict[d2].append(d1)
			break
	if not visit:
		break
	ans += 1
print(ans)


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = []
for i in range(n):
	b.append(list(map(int, input().split())))
b.sort()
a = sorted(a, key=lambda x: -x[1])
ans = 0
vb = []
for i in range(n):
	for j in range(n):
		if not j in vb:
			if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
				vb.append(j)
				ans += 1
				break
print(ans)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
blue = sorted(blue, key=lambda x: x[0])
ans = 0
for b in blue:
	for r in sorted([r_ for r_ in red if r_[0] < b[0]], key=lambda x: x[1], reverse=True):
		if r[1] < b[1]:
			ans += 1
			red.pop(red.index(r))
			break
print(ans)


n = int(input())
Rb = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1], reverse=True)
Bc = sorted([list(map(int, input().split())) for _ in range(n)])
cnt = 0
for (c, d) in Bc:
	for (a, b) in Rb:
		if a < c and b < d:
			Rb.remove([a, b])
			cnt += 1
			break
print(cnt)


n = int(input())
r = [tuple(map(int, input().split())) for _ in range(n)]
b = [tuple(map(int, input().split())) for _ in range(n)]
r = sorted(r)
b = sorted(b)
for (x, y) in b:
	(p, q) = (-1, -1)
	for (i, j) in r:
		if i < x and j < y and (j > q):
			(p, q) = (i, j)
	if (p, q) in r:
		r.remove((p, q))
print(n - len(r))


n = int(input())
r = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(n)]
b.sort()
(d, ans) = (dict(), 0)
for i in range(n):
	cnt = -1
	ok = False
	for j in range(n):
		if j not in d:
			if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
				if r[j][1] > cnt:
					cnt = r[j][1]
					k = j
					ok = True
	if ok:
		ans += 1
		d[k] = 0
print(ans)


n = int(input())
ab = [tuple(map(int, input().split())) for _ in [0] * n]
cd = [tuple(map(int, input().split())) for _ in [0] * n]
ab.sort(reverse=True)
cd.sort(key=lambda x: x[1])
cnt = 0
for (a, b) in ab:
	flag = False
	for (c, d) in cd:
		if a < c and b < d:
			cnt += 1
			flag = True
			break
	if flag == True:
		cd.remove((c, d))
print(cnt)


from operator import itemgetter
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1), reverse=True)
CD = [tuple(map(int, input().split())) for _ in range(N)]
CD.sort(key=itemgetter(0))
use = [False] * N
for (a, b) in AB:
	for (i, (c, d)) in enumerate(CD):
		if a < c and b < d and (not use[i]):
			use[i] = True
			break
print(sum(use))


N = int(input())
Red = [list(map(int, input().split())) for i in range(N)]
Blue = [list(map(int, input().split())) for i in range(N)]
Red.sort(reverse=True)
Blue.sort(key=lambda x: x[1])
count = 0
for red in Red:
	for blue in Blue:
		if red[0] < blue[0] and red[1] < blue[1]:
			count += 1
			Blue.pop(Blue.index(blue))
			break
print(count)


n = int(input())
red = [[] for i in range(n)]
blue = [[] for i in range(n)]
for i in range(n):
	(a, b) = list(map(int, input().split()))
	red[i].append(a)
	red[i].append(b)
for i in range(n):
	(a, b) = list(map(int, input().split()))
	blue[i].append(a)
	blue[i].append(b)
red = sorted(red)
blue = sorted(blue)
ans = 0
for i in range(n):
	x = blue[i][0]
	y = blue[i][1]
	maxy = -1
	for j in range(n):
		if x > red[j][0] and y > red[j][1]:
			maxy = max(maxy, red[j][1])
	for j in range(n):
		if x > red[j][0] and maxy == red[j][1]:
			ans += 1
			red[j][0] = 1000
			break
print(ans)


n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab.sort()
cd.sort()
cnt = 0
for (i, j) in cd:
	x = []
	for (k, l) in ab:
		if k < i and l < j:
			x.append([k, l])
	if len(x) > 0:
		cnt += 1
		xx = sorted(x, key=lambda x: x[1])
		ab.remove(xx[-1])
print(cnt)


N = int(input())
ab = [[int(i) for i in input().split(' ')] for _ in range(N)]
cd = [[int(i) for i in input().split(' ')] for _ in range(N)]
ab_sort = sorted(ab, key=lambda x: -x[1])
cd_sort = sorted(cd, key=lambda x: x[0])
cnt = 0
for (c, d) in cd_sort:
	for (a, b) in ab_sort:
		if a < c and b < d:
			ab_sort.remove([a, b])
			cnt += 1
			break
print(cnt)


n = int(input())
s = [list(map(int, input().split())) for _ in range(n)]
t = [list(map(int, input().split())) + [1] for _ in range(n)]
ss = sorted(s, key=lambda x: x[1], reverse=True)
tt = sorted(t, key=lambda x: x[0])
cnt = 0
for i in range(n):
	for j in range(n):
		if ss[i][0] < tt[j][0] and ss[i][1] < tt[j][1] and (tt[j][2] == 1):
			cnt += 1
			tt[j][2] -= 1
			break
print(cnt)


N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]
ab = sorted(ab, key=lambda x: x[1])
cd.sort()
count = 0
for i in range(N):
	idx = -1
	for j in range(len(ab)):
		if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
			idx = j
	if idx >= 0:
		count += 1
		ab.pop(idx)
print(count)


import sys
input = sys.stdin.readline

class FordFulkerson:

	def __init__(self, n):
		self.N = n
		self.G = [[] for _ in range(n)]

	def add_edge(self, fr, to, cap):
		forward = [to, cap, None]
		forward[2] = backward = [fr, 0, forward]
		self.G[fr].append(forward)
		self.G[to].append(backward)

	def add_multi_edge(self, v1, v2, cap1, cap2):
		edge1 = [v2, cap1, None]
		edge1[2] = edge2 = [v1, cap2, edge1]
		self.G[v1].append(edge1)
		self.G[v2].append(edge2)

	def dfs(self, v, t, f):
		if v == t:
			return f
		used = self.used
		used[v] = 1
		for e in self.G[v]:
			(w, cap, rev) = e
			if cap and (not used[w]):
				d = self.dfs(w, t, min(f, cap))
				if d:
					e[1] -= d
					rev[1] += d
					return d
		return 0

	def flow(self, s, t):
		flow = 0
		f = INF = 10 ** 9 + 7
		N = self.N
		while f:
			self.used = [0] * N
			f = self.dfs(s, t, INF)
			flow += f
		return flow

def main():
	n = int(input())
	red = [list(map(int, input().split())) for _ in range(n)]
	blue = [list(map(int, input().split())) for _ in range(n)]
	flow = FordFulkerson(n * 2 + 2)
	for i in range(n):
		flow.add_edge(0, i + 1, 1)
		flow.add_edge(n + i + 1, 2 * n + 1, 1)
		for j in range(n):
			if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
				flow.add_edge(i + 1, n + j + 1, 1)
	ans = flow.flow(0, 2 * n + 1)
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys

def input():
	return sys.stdin.readline().strip()

def mapint():
	return map(int, input().split())
sys.setrecursionlimit(10 ** 9)
from bisect import bisect_right
N = int(input())
ab = [list(mapint()) for _ in range(N)]
cd = [list(mapint()) for _ in range(N)]
ab.sort(reverse=True)
cd.sort(key=lambda x: x[1])
checked = [0] * N
ans = 0
for n in range(N):
	(a, b) = ab[n]
	for i in range(N):
		if checked[i]:
			continue
		(c, d) = cd[i]
		if a < c and b < d:
			ans += 1
			checked[i] = 1
			break
print(ans)


n = int(input())
r = [tuple(map(int, input().split())) for i in range(n)]
b = [tuple(map(int, input().split())) for i in range(n)]
r.sort(key=lambda x: x[1], reverse=True)
b.sort(key=lambda x: x[0])
selected = [0] * n
ans = 0
for i in range(n):
	(bx, by) = b[i]
	j = 0
	while j < n:
		(rx, ry) = r[j]
		if bx > rx and by > ry and (selected[j] == 0):
			ans += 1
			selected[j] = 1
			break
		j += 1
print(ans)


N = int(input())
reds = []
for i in range(N):
	(a, b) = list(map(int, input().split()))
	reds.append([a, b])
reds.sort(key=lambda x: x[1], reverse=True)
blues = []
for i in range(N):
	(c, d) = list(map(int, input().split()))
	blues.append([c, d])
blues.sort()
flag = [False for i in range(N)]
ans = 0
for i in range(N):
	(c, d) = (blues[i][0], blues[i][1])
	for j in range(N):
		if flag[j] == True:
			continue
		(a, b) = (reds[j][0], reds[j][1])
		if c > a and d > b:
			flag[j] = True
			ans += 1
			break
print(ans)


N = int(input())
AB = [tuple((int(_) for _ in input().split())) for i in range(N)]
CD = [tuple((int(_) for _ in input().split())) for i in range(N)]
AB.sort(key=lambda xy: xy[1], reverse=True)
CD.sort()
for (c, d) in CD:
	for (a, b) in AB:
		if a < c and b < d:
			AB.remove((a, b))
			break
print(N - len(AB))


import sys
input = sys.stdin.readline
from collections import deque

class HopcroftKarp:

	def __init__(self, N0, N1):
		self.N0 = N0
		self.N1 = N1
		self.N = N = 2 + N0 + N1
		self.G = [[] for i in range(N)]
		for i in range(N0):
			forward = [2 + i, 1, None]
			forward[2] = backward = [0, 0, forward]
			self.G[0].append(forward)
			self.G[2 + i].append(backward)
		self.backwards = bs = []
		for i in range(N1):
			forward = [1, 1, None]
			forward[2] = backward = [2 + N0 + i, 0, forward]
			bs.append(backward)
			self.G[2 + N0 + i].append(forward)
			self.G[1].append(backward)

	def add_edge(self, fr, to):
		v0 = 2 + fr
		v1 = 2 + self.N0 + to
		forward = [v1, 1, None]
		forward[2] = backward = [v0, 0, forward]
		self.G[v0].append(forward)
		self.G[v1].append(backward)

	def bfs(self):
		G = self.G
		level = [None] * self.N
		deq = deque([0])
		level[0] = 0
		while deq:
			v = deq.popleft()
			lv = level[v] + 1
			for (w, cap, _) in G[v]:
				if cap and level[w] is None:
					level[w] = lv
					deq.append(w)
		self.level = level
		return level[1] is not None

	def dfs(self, v, t):
		if v == t:
			return 1
		level = self.level
		for e in self.it[v]:
			(w, cap, rev) = e
			if cap and level[v] < level[w] and self.dfs(w, t):
				e[1] = 0
				rev[1] = 1
				return 1
		return 0

	def flow(self):
		flow = 0
		G = self.G
		bfs = self.bfs
		dfs = self.dfs
		while bfs():
			(*self.it,) = map(iter, G)
			while dfs(0, 1):
				flow += 1
		return flow

	def matching(self):
		return [cap for (_, cap, _) in self.backwards]
n = int(input())
solve = HopcroftKarp(n, n)
(red, blue) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	red.append([a, b])
for i in range(n):
	(c, d) = map(int, input().split())
	blue.append([c, d])
for i in range(n):
	for j in range(n):
		if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
			solve.add_edge(i, j)
print(solve.flow())


n = int(input())
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort(key=lambda x: x[1])
blue.sort()
count = 0
for (xb, yb) in blue:
	max_y = -1
	max_i = -1
	for i in range(n):
		(xr, yr) = red[i]
		if xb > xr and yb > yr and (max_y < yr):
			(max_y, max_i) = (yr, i)
	if max_y >= 0:
		red[max_i] = (201, 201)
		count += 1
print(count)


n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
li = [list(map(int, input().split())) for i in range(n)]
lis.sort(key=lambda x: x[1], reverse=True)
li.sort()
ans = 0
for (lisx, lisy) in lis:
	for (lix, liy) in li:
		if lisx < lix and lisy < liy:
			ans += 1
			li.remove([lix, liy])
			break
print(ans)


N = int(input())
Red = []
for i in range(N):
	Red.append(list(map(int, input().split())))
Blue = []
for i in range(N):
	Blue.append(list(map(int, input().split())))
Red = sorted(Red, key=lambda x: -x[1])
Blue.sort()
res = 0
for i in range(N):
	for j in range(len(Blue)):
		if Red[i][0] < Blue[j][0] and Red[i][1] < Blue[j][1]:
			res += 1
			del Blue[j]
			break
print(res)


N = int(input())
red = [[int(i) for i in input().split()] for j in range(N)]
blue = [[int(i) for i in input().split()] for j in range(N)]
red.sort(key=lambda x: x[1])
red.reverse()
blue.sort()
ans = 0
while blue:
	bA = blue.pop(0)
	for i in range(len(red)):
		rA = red[i]
		if bA[0] > rA[0] and bA[1] > rA[1]:
			red.pop(i)
			ans += 1
			break
print(ans)


import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
sys.setrecursionlimit(10000000)
N = int(input())
AB = []
CD = []
for i in range(N):
	(A, B) = map(int, input().split())
	AB.append((A, B))
for i in range(N):
	(C, D) = map(int, input().split())
	CD.append((C, D))
AB.sort()
CD.sort()
used = [False] * N
cnt = 0
for i in range(N):
	m = -1
	for j in range(N):
		if not used[j] and CD[i][0] > AB[j][0] and (CD[i][1] > AB[j][1]):
			if m < 0 or AB[m][1] < AB[j][1]:
				m = j
	if m >= 0:
		used[m] = True
		cnt += 1
print(cnt)


from operator import itemgetter
N = int(input())
A = [tuple(map(int, input().split())) for i in range(N)]
B = [tuple(map(int, input().split())) for i in range(N)]
A.sort()
B.sort()
num = 0
for i in range(N):
	K = [A[k] for k in range(len(A)) if A[k][0] < B[i][0] and A[k][1] < B[i][1]]
	if K:
		num += 1
		t = sorted(K, key=itemgetter(1))[-1]
		A.remove(t)
print(num)


N = int(input())
r = [[int(i) for i in input().split()] for _ in range(N)]
b = [[int(i) for i in input().split()] for _ in range(N)]
b1 = sorted(b)
r1 = sorted(r, key=lambda x: x[1])[::-1]
cnt = 0
for ib in b1:
	for ir in r1:
		if ir[0] < ib[0] and ir[1] < ib[1]:
			cnt += 1
			r1.remove(ir)
			break
print(cnt)


n = int(input())
R = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	R.append((a, b))
B = []
for i in range(n):
	(c, d) = list(map(int, input().split()))
	B.append((c, d))
R.sort(reverse=True)
B.sort(key=lambda x: x[1])
ans = 0
for i in R:
	for j in range(len(B)):
		if i[0] < B[j][0] and i[1] < B[j][1]:
			ans += 1
			B.pop(j)
			break
print(ans)


N = int(input())
reds = [tuple(map(int, input().split())) for _ in range(N)]
blues = [tuple(map(int, input().split())) for _ in range(N)]
reds.sort(key=lambda x: -x[1])
blues.sort(key=lambda x: x[0])
ans = 0
usedreds = [False] * N
usedblues = [False] * N
for i in range(N):
	if usedreds[i]:
		continue
	(a, b) = reds[i]
	for j in range(N):
		if usedblues[j]:
			continue
		(c, d) = blues[j]
		if not (a < c and b < d):
			continue
		ans += 1
		usedreds[i] = True
		usedblues[j] = True
		break
print(ans)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
res = 0
red.sort(key=lambda x: x[1], reverse=True)
blue.sort()
for i in range(n):
	for j in range(len(red)):
		if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
			red.pop(j)
			res += 1
			break
print(res)


from collections import deque
n = int(input())
r = []
b = []
for i in range(n):
	r.append(list(map(int, input().split())))
for i in range(n):
	b.append(list(map(int, input().split())))
r.sort(key=lambda x: x[1], reverse=True)
b.sort()
for bi in b:
	for i in range(len(r)):
		if r[i][0] < bi[0] and r[i][1] < bi[1]:
			r = r[:i] + r[i + 1:]
			break
print(n - len(r))


n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
red.sort(key=lambda x: x[1], reverse=True)
blue = [list(map(int, input().split())) for i in range(n)]
blue = sorted(blue)
ans = 0
for (x_b, y_b) in blue:
	for (x_r, y_r) in red:
		if x_r < x_b and y_r < y_b:
			red.remove([x_r, y_r])
			ans += 1
			break
print(ans)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
blue.sort()
res = 0
for (bx, by) in blue:
	dist = -1
	for (rx, ry) in red:
		if rx < bx and dist < ry < by:
			dist = ry
			(mx, my) = (rx, ry)
	if dist > -1:
		res += 1
		red.remove([mx, my])
print(res)


n = int(input())
r = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
r = sorted(r, key=lambda x: x[0] * 2 * n + x[1])
b = sorted(b, key=lambda x: x[0] * 2 * n - x[1])
cnt = 0
i = 0
while i != n:
	t = [0, 0]
	for (x, y) in r:
		if x < b[i][0] and y < b[i][1] and (t[1] <= y):
			t = [x, y]
	if t in r:
		r.remove(t)
		cnt += 1
	i += 1
print(cnt)


N = int(input())
Red = [list(map(int, input().split())) for _ in range(N)]
Blue = [list(map(int, input().split())) for _ in range(N)]
Red.sort(key=lambda x: x[1], reverse=True)
Blue.sort(key=lambda x: x[0])
ans = 0
for blue in Blue:
	for red in Red:
		if red[0] < blue[0] and red[1] < blue[1]:
			ans += 1
			Red.remove(red)
			break
print(ans)


N = int(input())
A = [list(map(int, input().split())) for l in range(N)]
B = [list(map(int, input().split())) for l in range(N)]
A.sort()
B.sort()
for i in range(N):
	a = -5
	b = -1
	for j in range(len(A)):
		if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
			if a < A[j][1]:
				a = A[j][1]
				b = j
	if b != -1:
		del A[b]
print(N - len(A))


from operator import itemgetter as get
(N, *L) = map(int, open(0).read().split())
L1 = L[:N * 2]
L2 = L[N * 2:]
R = sorted([(x, y) for (x, y) in zip(*[iter(L1)] * 2)], key=get(1), reverse=1)
B = sorted([(x, y) for (x, y) in zip(*[iter(L2)] * 2)])
cnt = 0
for (bx, by) in B:
	for (rx, ry) in R:
		if rx < bx and ry < by:
			R.remove((rx, ry))
			cnt += 1
			break
print(cnt)


def ans():
	N = int(input())
	AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
	CD = sorted([list(map(int, input().split())) for _ in range(N)])
	cnt = 0
	for (c, d) in CD:
		for (a, b) in AB:
			if a < c and b < d:
				cnt += 1
				AB.remove([a, b])
				break
	print(cnt)
ans()


N = int(input())
rn = [[True] + list(map(int, input().split())) for _ in range(N)]
bn = sorted([list(map(int, input().split())) for _ in range(N)])
rn.sort(key=lambda x: -x[2])
for bp in bn:
	(bx, by) = bp
	for rp in rn:
		(f, rx, ry) = rp
		if f and rx < bx and (ry < by):
			rp[0] = False
			break
print(sum([0 if rp[0] else 1 for rp in rn]))


N = int(input())
r = []
for i in range(N):
	r.append(list(map(int, input().split())))
b = []
for i in range(N):
	b.append(list(map(int, input().split())))
r = sorted(r, key=lambda x: x[0])
b = sorted(b, key=lambda x: x[0])
r_selected = [False] * N
ans = 0
for i in range(N):
	y_max = -1
	j_selected = -1
	for j in range(N):
		if r_selected[j]:
			continue
		if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
			if y_max < r[j][1]:
				y_max = r[j][1]
				j_selected = j
	if y_max == -1:
		continue
	else:
		r_selected[j_selected] = True
print(r_selected.count(True))


N = int(input())
red = [list(map(int, input().split())) for i in range(N)]
blue = [list(map(int, input().split())) for i in range(N)]
a = [0] * N
for (x, y) in sorted(blue, key=lambda x: x[0]):
	k = []
	for (i, [x2, y2]) in enumerate(red):
		if x2 < x and y2 < y and (not a[i]):
			k.append((x2, y2, i))
	if len(k):
		(x, y, i) = sorted(k, key=lambda x: -1 * x[1])[0]
		a[i] = 1
print(sum(a))


from sys import stdin
input = stdin.readline

def main():
	N = int(input())
	R = [tuple(map(int, input().split())) for _ in range(N)]
	B = [tuple(map(int, input().split())) for _ in range(N)]
	num_friends = 0
	B.sort(key=lambda x: x[0])
	for (ib, b) in enumerate(B):
		(bx, by) = (b[0], b[1])
		tmp_r = (-1, -1)
		for (ir, r) in enumerate(R):
			(rx, ry) = (r[0], r[1])
			if rx < bx and ry < by and (tmp_r[1] < ry):
				tmp_r = r
		if tmp_r == (-1, -1):
			continue
		num_friends += 1
		R.remove(tmp_r)
	print(num_friends)
main()


n = int(input())
cr = [tuple(map(int, input().split())) for _ in range(n)]
cb = [tuple(map(int, input().split())) for _ in range(n)]
cb.sort(key=lambda xy: xy[0])
cr.sort(key=lambda xy: xy[1], reverse=True)
npair = 0
for (bx, by) in cb:
	for (rx, ry) in cr:
		if rx < bx and ry < by:
			npair += 1
			cr.remove((rx, ry))
			break
print(npair)


n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
	for (num, j) in enumerate(blue):
		if i[0] < j[0] and i[1] < j[1]:
			ans += 1
			del blue[num]
			break
print(ans)


n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]
red.sort(reverse=True, key=lambda x: x[1])
blue.sort()
ans = 0
for i in range(len(blue)):
	(c, d) = blue[i]
	for j in range(len(red)):
		(a, b) = red[j]
		if a < c and b < d:
			del red[j]
			ans += 1
			break
print(ans)


N = int(input())
r = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda q: q[0], reverse=True)
b = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda q: q[1])
ans = 0
for (rx, ry) in r:
	for i in range(len(b)):
		(bx, by) = b[i]
		if bx > rx and by > ry:
			ans += 1
			b.pop(i)
			break
print(ans)


N = int(input())
reds = [tuple(map(int, input().split())) for _ in range(N)]
blues = [tuple(map(int, input().split())) for _ in range(N)]
reds.sort(key=lambda x: x[1], reverse=True)
blues.sort(key=lambda x: x[0])
ans = 0
for b in blues:
	for (i, r) in enumerate(reds):
		if b[0] > r[0] and b[1] > r[1]:
			ans += 1
			del reds[i]
			break
print(ans)


N = int(input())
rs = [tuple(map(int, input().split())) for i in range(N)]
bs = [tuple(map(int, input().split())) for i in range(N)]
bs.sort()
rs.sort(key=lambda x: -x[1])
removed = [0] * N
ans = 0
for (bx, by) in bs:
	for ri in range(N):
		if removed[ri]:
			continue
		(rx, ry) = rs[ri]
		if rx < bx and ry < by:
			removed[ri] = 1
			ans += 1
			break
print(ans)


import networkx as nx
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
ab = sorted(ab)
cd = [list(map(int, input().split())) for _ in range(N)]
cd = sorted(cd, reverse=True)
G = nx.DiGraph()
for i in range(N):
	G.add_edge('x', i, capacity=1)
	for j in range(N):
		if i == 0:
			G.add_edge(N + j, 'y', capacity=1)
		(a, b) = ab[i]
		(c, d) = cd[j]
		if a < c and b < d:
			G.add_edge(i, N + j, capacity=1)
		elif a >= c:
			break
(flow_value, flow_dict) = nx.maximum_flow(G, 'x', 'y')
print(flow_value)


N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]
ab.sort()
cd.sort()
g = [[] for _ in range(N)]
for (i, pab) in enumerate(ab):
	for (j, pcd) in enumerate(cd):
		if pab[0] < pcd[0] and pab[1] < pcd[1]:
			g[j].append([pab[1], i])
ans = 0
s = set()
for gg in g:
	gg.sort(reverse=True)
	for ggg in gg:
		if ggg[1] in s:
			continue
		else:
			ans += 1
			s.add(ggg[1])
			break
print(ans)


n = int(input())
(red, blue) = ([], [])
ans = 0
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	red.append((max(a, b), a, b))
for _ in range(n):
	(c, d) = list(map(int, input().split()))
	blue.append((min(c, d), c, d))
red.sort(key=lambda x: x[0], reverse=True)
blue.sort(key=lambda x: x[0])
for i in range(n):
	(_, xb, yb) = blue[i]
	for j in range(n):
		if red[j]:
			(_, xr, yr) = red[j]
			if xb > xr and yb > yr:
				red[j] = False
				ans += 1
				break
print(ans)


from operator import itemgetter
n = int(input())
A = [tuple(map(int, input().split())) for i in range(n)]
B = [tuple(map(int, input().split())) for j in range(n)]
A.sort()
B.sort()
count = 0
for i in range(n):
	box = [A[j] for j in range(len(A)) if A[j][0] < B[i][0] and A[j][1] < B[i][1]]
	if any(box):
		box = sorted(box, key=itemgetter(1))
		A.remove(box[-1])
		count += 1
print(count)


n = int(input())
ab = sorted([[int(i) for i in input().split()] for i in range(n)], reverse=True, key=lambda x: x[1])
cd = sorted([[int(i) for i in input().split()] for i in range(n)])
count = 0
for i in range(n):
	for j in range(len(cd)):
		if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
			count += 1
			del cd[j]
			break
print(count)


N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
blue.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
	maxy = -1
	maxyidx = 0
	for j in range(N):
		if blue[i][0] > red[j][0] and blue[i][1] > red[j][1] and (red[j][1] > maxy):
			maxy = red[j][1]
			maxyidx = j
	if maxy > -1:
		ans += 1
		red[maxyidx][1] = -1
print(ans)


n = int(input())
red = [[0] * 2 for _ in range(n)]
blue = [[0] * 2 for _ in range(n)]
for i in range(n):
	(red[i][1], red[i][0]) = list(map(int, input().split()))
for i in range(n):
	(blue[i][0], blue[i][1]) = list(map(int, input().split()))
red.sort(reverse=True)
blue.sort()
ans = 0
usedred = [False] * n
for i in range(n):
	for j in range(n):
		if blue[i][0] > red[j][1] and blue[i][1] > red[j][0] and (usedred[j] != True):
			ans += 1
			usedred[j] = True
			break
print(ans)


n = int(input())
red = []
for i in range(n):
	red.append([int(j) for j in input().split()])
red.sort(key=lambda x: x[1], reverse=True)
blue = []
for i in range(n):
	blue.append([int(j) for j in input().split()])
blue.sort()
count = 0
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			count += 1
			red.remove(r)
			break
print(count)


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(n)]
b.sort(key=lambda x: x[0])
a.sort(key=lambda x: x[1])
seen = [0] * n
count = 0
for i in range(n):
	for j in range(n):
		if seen[j] == 0 and a[-(i + 1)][0] < b[j][0] and (a[-(i + 1)][1] < b[j][1]):
			seen[j] = 1
			count = count + 1
			break
print(count)


n = int(input())
a = []
b = []
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	b.append(list(map(int, input().split())))
an = sorted(a, key=lambda x: -x[1])
bn = sorted(b)
count = 0
for i in range(len(bn)):
	for j in range(len(an)):
		if bn[i][0] > an[j][0] and bn[i][1] > an[j][1]:
			count += 1
			an.pop(j)
			break
print(count)


from operator import itemgetter
n = int(input())
r = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(n)]
r.sort()
b.sort()
ct = 0
for i in range(n):
	x = b[i][0]
	y = b[i][1]
	L = []
	for j in range(len(r)):
		if r[j][0] < x and r[j][1] < y:
			L.append(r[j])
		L = sorted(L, key=itemgetter(1))
	if len(L) > 0:
		r.remove(L[len(L) - 1])
		ct += 1
print(ct)


(n, *ABCD) = map(int, open(0).read().split())
AB = sorted([(a, b) for (a, b) in zip(ABCD[:2 * n:2], ABCD[1:2 * n:2])], key=lambda x: -x[1])
CD = sorted([(c, d) for (c, d) in zip(ABCD[2 * n::2], ABCD[2 * n + 1::2])])
for (c, d) in CD:
	for i in range(len(AB)):
		(a, b) = AB[i]
		if a < c and b < d:
			_ = AB.pop(i)
			break
print(n - len(AB))


N = int(input())
R = [[int(x) for x in input().split()] for _ in range(N)]
B = [[int(x) for x in input().split()] for _ in range(N)]
import operator
R.sort(key=operator.itemgetter(1), reverse=True)
B.sort()
ans = 0
for b in B:
	(xb, yb) = b
	for r in R:
		(xr, yr) = r
		if xr < xb and yr < yb:
			ans += 1
			R.remove(r)
			break
print(ans)


n = int(input())
redlist = [list(map(int, input().split())) for _ in range(n)]
bluelist = [list(map(int, input().split())) for _ in range(n)]
redlist.sort(key=lambda x: x[1], reverse=True)
bluelist.sort(key=lambda x: x[0])
output = 0
for blue in bluelist:
	for red in redlist:
		if blue[1] > red[1] and blue[0] > red[0]:
			output += 1
			redlist.remove(red)
			break
print(output)


n = int(input())
lst_r = [list(map(int, input().split())) for _ in range(n)]
lst_b = [list(map(int, input().split())) for _ in range(n)]
lst_r.sort(key=lambda x: -x[1])
lst_b.sort()
ans = 0
for b in lst_b:
	for r in lst_r:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			lst_r.remove(r)
			break
print(ans)


n = int(input())
ab = []
for i in range(n):
	ab.append(list(map(int, input().split())))
cd = []
for i in range(n):
	cd.append(list(map(int, input().split())))
cd.sort()
ab.sort(key=lambda x: x[1], reverse=True)
flag_ab = [False for i in range(n)]
count = 0
for i in range(n):
	(c, d) = (cd[i][0], cd[i][1])
	for j in range(n):
		if flag_ab[j] == True:
			continue
		(a, b) = (ab[j][0], ab[j][1])
		if c > a and d > b:
			flag_ab[j] = True
			count += 1
			break
print(count)


N = int(input())
red = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1], reverse=True)
blue = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in blue:
	for j in red:
		if i[0] > j[0] and i[1] > j[1]:
			cnt += 1
			red.remove(j)
			break
print(cnt)


N = int(input())
red = [tuple(map(int, input().split())) for _ in range(N)]
blue = [tuple(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x: x[0], reverse=True)
blue.sort(key=lambda x: x[1])
ans = 0
for i in range(N):
	(a, b) = red[i]
	for j in range(len(blue)):
		(c, d) = blue[j]
		if a < c and b < d:
			blue.pop(j)
			ans += 1
			break
print(ans)


import networkx as nx
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
match_list = [[] for i in range(n)]
for i in range(n):
	for j in range(n):
		(a, b) = ab[i]
		(c, d) = cd[j]
		if a < c and b < d:
			match_list[i].append(j)
group1 = list(range(n))
group2 = list(range(n, 2 * n))
g = nx.Graph()
g.add_nodes_from(group1, bipartite=1)
g.add_nodes_from(group2, bipartite=0)
for (i, list_) in enumerate(match_list):
	for j in list_:
		g.add_edge(i, j + n, weight=1)
d = nx.max_weight_matching(g)
print(len(d))


n = int(input())
l1 = [[int(i) for i in input().split()] for i in range(n)]
l2 = [[int(i) for i in input().split()] for i in range(n)]
l1.sort(key=lambda x: x[0], reverse=True)
l2.sort(key=lambda x: x[1])
answer = 0
for (a, b) in l1:
	for (c, d) in l2:
		if a < c and b < d:
			answer += 1
			l2.remove([c, d])
			break
print(answer)


N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x: x[1])
cd.sort()
c = 0
for i in range(N):
	k = -1
	for j in range(len(ab)):
		if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
			k = j
	if k != -1:
		c += 1
		ab = ab[:k] + ab[k + 1:]
print(c)


N = int(input())
AB = [list(map(int, input().split(' '))) for _ in range(N)]
CD = [list(map(int, input().split(' '))) for _ in range(N)]
CD.sort()
AB.sort(key=lambda x: (x[1], x[0]), reverse=True)
count = 0
for (c, d) in CD:
	for (j, (a, b)) in enumerate(AB):
		if a < c and b < d:
			count += 1
			AB.pop(j)
			break
print(count)


(n, *t) = map(int, open(0).read().split())
x = sorted(zip(t[1:n * 2:2], t[:n * 2:2]))
y = sorted(zip(t[n * 2::2], t[n * 2 + 1::2]))[::-1]
c = 0
while y:
	(i, j) = y.pop()
	k = len(x) - 1
	while k >= 0:
		(b, a) = x[k]
		if a < i and b < j:
			c += 1
			del x[k]
			break
		k -= 1
print(c)


n = int(input())
red = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[1], reverse=True)
blue = sorted([list(map(int, input().split())) for i in range(n)])
ans = 0
for (bx, by) in blue:
	for (rx, ry) in red:
		if rx < bx and ry < by:
			ans += 1
			red.remove([rx, ry])
			break
print(ans)


from operator import itemgetter
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(1), reverse=True)
B = sorted(B, key=itemgetter(0))
count = 0
for (c, d) in B:
	for (a, b) in R:
		if (a < c) & (b < d):
			count += 1
			R.remove((a, b))
			break
print(count)


n = int(input())
(red, blue) = ([], [])
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	red.append([a, b, min(a, b)])
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	blue.append([a, b, min(a, b)])
red.sort(key=lambda x: x[1])
blue.sort(key=lambda x: x[0])
status = [False for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(n - 1, -1, -1):
		if not status[j]:
			if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
				ans += 1
				status[j] = True
				break
print(ans)


import sys
sys.setrecursionlimit(10 ** 8)

def ii():
	return int(sys.stdin.readline())

def mi():
	return map(int, sys.stdin.readline().split())

def li():
	return list(map(int, sys.stdin.readline().split()))

def li2(N):
	return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def dp2(ini, i, j):
	return [[ini] * i for _ in range(j)]

def dfs(v, visited):
	for u in edges[v]:
		if u in visited:
			continue
		visited.add(u)
		if matched[u] == -1 or dfs(matched[u], visited):
			matched[u] = v
			return True
	return False
N = ii()
xn = N
yn = N
edges = [set() for _ in range(xn)]
matched = [-1] * yn
A = li2(N)
B = li2(N)
for i in range(N):
	for j in range(N):
		if A[i][0] < B[j][0] and A[i][1] < B[j][1]:
			edges[i].add(j)
print(sum((dfs(s, set()) for s in range(xn))))


n = int(input())
AB = list((list(map(int, input().split())) for _ in range(n)))
CD = list((list(map(int, input().split())) for _ in range(n)))
CD.sort()
AB.sort(key=lambda x: x[1], reverse=True)
dim_r = [[] for _ in range(n)]
dim_b = [[] for _ in range(n)]
for b in range(n):
	(bx, by) = CD[b]
	for r in range(n):
		(rx, ry) = AB[r]
		if rx < bx and ry < by:
			dim_r[r] += [b]
			dim_b[b] += [r]
ans = 0
inf = 1000000000
vis_r = [False] * n
for b in range(n):
	(bx, by) = CD[b]
	max_ry = -1
	max_r = -1
	for r in dim_b[b]:
		if vis_r[r]:
			continue
		(rx, ry) = AB[r]
		if max_ry < ry:
			max_ry = ry
			max_r = r
	if max_r >= 0:
		vis_r[max_r] = True
		ans += 1
print(ans)


N = int(input())
reds = sorted([tuple(map(int, input().split())) for _ in range(N)], reverse=True, key=lambda x: x[1])
blues = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans = 0
for b in blues:
	for r in reds:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			reds.remove(r)
			break
print(ans)


N = int(input())
red = [list(map(int, input().split())) for i in range(N)]
blue = [list(map(int, input().split())) for i in range(N)]
red.sort(key=lambda x: x[1], reverse=True)
blue.sort()
c = 0
for (bx, by) in blue:
	for (i, (rx, ry)) in enumerate(red):
		if rx < bx and ry < by:
			c += 1
			red.pop(i)
			break
print(c)


n = int(input())
r = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
b.sort()
r = sorted(r, key=lambda x: -x[1])
ans = 0
for (i, b_) in enumerate(b):
	for (j, r_) in enumerate(r):
		if b_[0] > r_[0] and b_[1] > r_[1]:
			ans += 1
			del r[j]
			break
print(ans)