Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.

Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.

Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 100) — the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≤ a_{i}, b_{i} ≤ 1000) — the description of the i-th bottle.


-----Output-----

In a single line print a single integer — the answer to the problem.


-----Examples-----
Input
4
1 1
2 2
3 3
4 4

Output
4

Input
4
1 2
2 3
3 4
4 1

Output
0

Difficulty: MEDIUM
Tags: Complete search
Skill types: Complete search

Starter code:

Solutions:
n = int(input())
l = []
t = [0] * 1001
for i in range(n):
	l += [list(map(int, input().split()))]
t = [i[1] for i in l]
c = 0
for i in range(n):
	if t.count(l[i][0]) > 1:
		c += 1
	elif t.count(l[i][0]) == 1 and t.index(l[i][0]) != i:
		c += 1
	else:
		pass
print(n - c)


n = int(input())
B = []
A = []
c = 0
for i in range(n):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
for i in range(n):
	if A[i] not in B[:i] and A[i] not in B[i + 1:]:
		c += 1
print(c)


t = int(input())
ans = 0
lst = []
lst2 = []
while t:
	t -= 1
	(a, b) = map(int, input().split())
	lst.append(a)
	lst2.append(b)
for i in range(len(lst)):
	if lst[i] not in lst2[i + 1:] and lst[i] not in lst2[:i]:
		ans += 1
print(ans)


n = int(input())
(b, a) = ([], [])
for i in range(n):
	(x, y) = map(int, input().split())
	b.append(y)
	a.append(x)
c = a[:]
for i in range(n):
	if b[i] in a and a[i] != b[i]:
		for j in range(a.count(b[i])):
			try:
				c.remove(b[i])
			except:
				pass
	elif a[i] == b[i] and a.count(a[i]) > 1:
		for j in range(a.count(b[i]) - 1):
			try:
				c.remove(b[i])
			except:
				pass
print(len(c))


n = int(input())
a = []
b = []
for i in range(n):
	(ai, bi) = [int(x) for x in input().split()]
	a.append(ai)
	b.append(bi)
count = 0
index = 0
for item in a:
	counter = b.count(item)
	if counter == 0 or (counter == 1 and b[index] == item):
		count += 1
	index += 1
print(count)


import bisect
n = int(input())
opened = []

def binary_search(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1
data = []
for i in range(0, n):
	(ai, bi) = map(int, input().split())
	bisect.insort_left(data, [bi, ai])
a = [0] * n
b = [0] * n
for i in range(0, n):
	a[i] = data[i][1]
	b[i] = data[i][0]
opened = []
for i in range(0, n):
	pos = binary_search(b[:i] + b[i + 1:], a[i])
	if pos != -1:
		opened.append(a[i])
print(len(a) - len(opened))


n = int(input())
brand = [0] * n
open = [0] * n
for i in range(n):
	(brand[i], open[i]) = map(int, input().split())
opened = [False] * n
res = n
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if not opened[j] and brand[j] == open[i]:
			opened[j] = True
			res -= 1
print(res)


def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[n] = get()
	found = []
	opener = set()
	count = 0
	other = []
	for i in range(n):
		[a, b] = get()
		if a == b:
			found.append(a)
			other.append(b)
			continue
		found.append(a)
		opener.add(b)
	c = set(found)
	final = c - opener
	for i in final:
		count += found.count(i)
	for i in other:
		count -= found.count(i) - 1
	print(max(count, 0))
	if mode == 'file':
		f.close()
main()


from collections import defaultdict

def serej(bottles):
	unopened = defaultdict(set)
	for (i, bottle) in enumerate(bottles):
		unopened[bottle[0]].add(i + 1)
	for (i, bottle) in enumerate(bottles):
		if bottle[1] in unopened:
			unopened[bottle[1]] = unopened[bottle[1]].intersection({i + 1})
	return sum((len(x) for x in unopened.values()))
n = int(input())
bottles = []
for _ in range(n):
	bottles.append([int(x) for x in input().split(' ')])
print(serej(bottles))


def bottles(lst1, lst2):
	(flag, count) = (False, 0)
	for i in range(len(lst1)):
		for j in range(len(lst1)):
			if lst1[i] == lst2[j] and i != j:
				flag = True
				break
		if flag is False:
			count += 1
		flag = False
	return count
n = int(input())
(a, b) = (list(), list())
for z in range(n):
	pair = [int(y) for y in input().split()]
	a.append(pair[0])
	b.append(pair[1])
print(bottles(a, b))


n = int(input())
(a, b, p) = ([0] * n, [0] * n, {})
for i in range(n):
	(a[i], b[i]) = input().split()
	p[b[i]] = a[i] != b[i] or b[i] in p
print(sum((not a[i] in p or (p[a[i]] == 0 and a[i] == b[i]) for i in range(n))))


n = int(input())
arr = [None]
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	ans = [i, a, b]
	arr.append(ans)
result = 0
ans = [False for x in range(n + 1)]
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if j != i:
			if arr[i][1] == arr[j][2]:
				ans[i] = True
				break
for i in range(1, n + 1):
	if ans[i] == False:
		result += 1
print(result)


numberOfBottles = int(input())
a = []
d = []
bottles = [1] * numberOfBottles
for x in range(numberOfBottles):
	(x, y) = map(int, input().split())
	a.append(x)
	d.append(y)
for y in range(len(a)):
	for b in range(len(a)):
		if a[b] == d[y] and y != b:
			bottles[b] = 0
print(sum(bottles))


n = int(input())
a_ = []
b_ = []
for i in range(n):
	(a, b) = map(int, input().split())
	a_.append(a)
	b_.append(b)
c = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if a_[i] == b_[j]:
			break
	else:
		c += 1
print(c)


(l, l2, l3) = ([], [], [])
for i in range(int(input())):
	(x, y) = map(int, input().split())
	l.append(x)
	l2.append(y)
	l3.append(1)
for i in range(len(l)):
	for j in range(len(l2)):
		if l2[i] == l[j] and i != j:
			l3[j] = 0
print(sum(l3))


n = int(input())
arr = []
rra = []
for i in range(n):
	z = list(map(int, input().split()))
	rra.append(z[0])
	arr.append(z[1])
count = 0
for i in range(n):
	temp = arr[i]
	indexx = i
	arr.remove(temp)
	if rra[i] in arr:
		arr.insert(indexx, temp)
	else:
		count += 1
		arr.insert(indexx, temp)
print(count)


n = int(input())
(bottle_num, opens) = ([0] * n, [0] * n)
bottles = [0] * 1001
for i in range(n):
	(bottle_num[i], opens[i]) = map(int, input().split())
	bottles[bottle_num[i]] += 1
k = 0
for (i, num) in enumerate(opens):
	for (j, bottle) in enumerate(bottle_num):
		if i != j and num == bottle and bottles[bottle]:
			k += 1
			bottles[bottle] -= 1
print(n - k)


from collections import defaultdict
brands = defaultdict(list)
can_open = defaultdict(list)
n = int(input())
for bottle in range(n):
	(a, b) = map(int, input().split())
	brands[a].append(bottle)
	can_open[a].append((b, bottle))
opened = [False for _ in range(n)]
for brand in can_open:
	for b in can_open[brand]:
		if b[0] not in brands:
			continue
		for bottle in brands[b[0]]:
			if b[0] == brand and b[1] == bottle:
				continue
			opened[bottle] = True
res = 0
for v in opened:
	if not v:
		res += 1
print(res)


n = int(input())
al = []
bl = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	al.append(a)
	bl.append(b)
count = 0
for (i, bot) in enumerate(al):
	if bot in bl[:i] + bl[i + 1:]:
		count += 1
print(n - count)


n = int(input())
a = []
b = []
for i in range(0, n):
	(A, B) = input().split()
	a.append(int(A))
	b.append(int(B))
countr = 0
for i in range(0, n):
	if a[i] not in b:
		countr += 1
	elif a[i] == b[i]:
		if b.count(b[i]) == 1:
			countr += 1
print(countr)


n = int(input())
unopenable = []
openable = []
count = n
for i in range(n):
	bottle = [int(i) for i in input().split()]
	if bottle[0] in openable:
		count -= 1
		unopenable.append(0)
	else:
		unopenable.append(bottle[0])
	openable.append(bottle[1])
for i in range(n - 1):
	bottle = unopenable[i]
	if bottle != 0:
		if bottle in openable[i + 1:n]:
			count -= 1
print(count)


n = int(input())
a = []
b = []
for i in range(n):
	(ap, bp) = map(int, input().split())
	a.append(ap)
	b.append(bp)
ok = [False] * n
for i in range(n):
	for j in range(n):
		if b[i] == a[j] and i != j:
			ok[j] = True
print(ok.count(False))


def solve(n, a, b):
	cnt = 0
	for i in range(n):
		opener = a[i]
		for j in range(n):
			if i == j and opener == b[j]:
				continue
			elif i != j and opener != b[j]:
				continue
			elif opener == b[j]:
				cnt += 1
				break
	print(n - cnt)
n = int(input())
a = []
b = []
for i in range(n):
	(l, r) = map(int, input().split())
	a.append(l)
	b.append(r)
solve(n, a, b)


def solve():
	n = int(input())
	openers = []
	bottles = []
	for i in range(n):
		(a, b) = map(int, input().split())
		bottles.append(a)
		openers.append(b)
	score = 0
	for i in range(n):
		for j in range(n):
			if bottles[i] == openers[j] and i != j:
				score += 1
				break
	return n - score
print(solve())


def main():
	n = int(input())
	a = [None] * n
	b = [None] * n
	for i in range(n):
		(a[i], b[i]) = map(int, input().split())
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if a[j] == b[i]:
				a[j] = -1
	ans = 0
	for item in a:
		if item != -1:
			ans += 1
	print(ans)
main()


from bisect import *
import sys
input = sys.stdin.buffer.readline
import copy
n = int(input())
arr = []
brr = []
while n:
	n -= 1
	(a, b) = map(int, input().split())
	arr.append(a)
	brr.append(b)
ans = 0
for i in range(len(arr)):
	crr = copy.deepcopy(brr)
	crr.pop(i)
	if arr[i] in crr:
		ans += 1
print(len(arr) - ans)


n = int(input())
bottles = [list(map(int, input().split())) for i in range(n)]
b_left = n
for i in range(n):
	for j in range(n):
		if i != j and bottles[i][0] == bottles[j][1]:
			b_left -= 1
			break
print(b_left)


import sys
sys.setrecursionlimit(10000)
n = int(sys.stdin.readline())
arr = [0] * 1001
bottles = []
for i in range(n):
	(a, b) = [int(x) for x in input().strip().split()]
	bottles.append([a, b])
count = 0
for i in range(n):
	for j in range(n):
		if j != i and bottles[i][0] == bottles[j][1]:
			count += 1
			bottles[i][0] = 0
print(n - count)


n = int(input())
a = []
b = []
c = [0 for i in range(10000)]
for i in range(n):
	(e, f) = map(int, input().split())
	a.append(e)
	b.append(f)
	c[b[i]] += 1
count = 0
for i in range(n):
	c[b[i]] -= 1
	if c[a[i]] == 0:
		count += 1
	c[b[i]] += 1
print(count)


n = int(input())
list1 = []
list2 = []
openedBottles = []
for i in range(0, n + 1):
	list1.append(0)
	list2.append(0)
	openedBottles.append(0)
for i in range(1, n + 1):
	input1 = list(map(int, input().split(' ')))
	list1[i] = input1[0]
	list2[i] = input1[1]
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if i != j and list2[i] == list1[j]:
			openedBottles[j] = 1
answer = 0
for i in range(1, n + 1):
	answer += openedBottles[i]
print(n - answer)


n = int(input())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
k = 0
for i in range(n):
	for j in range(n):
		if i != j and a[i][0] == a[j][1]:
			k += 1
			break
print(n - k)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	ans = 0
	have = []
	for i in range(n):
		(a, b) = sep()
		have.append((a, b))
	for i in range(n):
		curr = have[i][0]
		f = False
		for j in range(n):
			if i == j:
				continue
			if have[j][1] == curr:
				f = True
		if not f:
			ans += 1
	print(ans)
testcase(1)


from collections import defaultdict
n = int(input())
a = []
b = []
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
s = defaultdict(int)
for i in a:
	s[i] += 1
d = set()
op = 0
for i in range(n):
	if a[i] != b[i]:
		if b[i] in s and b[i] not in d:
			op += s[b[i]]
			d.add(b[i])
	elif s[b[i]] > 1:
		if b[i] not in d:
			op += s[b[i]] - 1
			d.add(b[i])
		else:
			op += 1
print(max(n - op, 0))


n = int(input())
a = []
b = []
c = [1] * n
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
for i in range(n):
	for j in range(n):
		if a[j] == b[i] and i != j:
			c[j] = 0
print(sum(c))


n = int(input())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
c = 0
for i in range(n):
	flag = False
	for j in range(n):
		if l[i][0] == l[j][1] and i != j:
			flag = True
			break
	if not flag:
		c += 1
print(c)


a = int(input())
i = 0
d = 0
x = []
y = []
for i in range(0, a, 1):
	(b, c) = input().split(' ')
	b = int(b)
	c = int(c)
	x.append(b)
	y.append(c)
i = 0
z = []
for i in range(0, a, 1):
	b = y[i]
	j = i
	m = 0
	for m in range(0, j, 1):
		if x[m] == y[i]:
			z.append(m + 1)
	j += 1
	m = j
	for m in range(j, a, 1):
		if x[m] == y[i]:
			z.append(m + 1)
z = sorted(z)
l = len(z)
f = 1
for f in range(1, a + 1, 1):
	i = 0
	e = 0
	for i in range(0, l, 1):
		if z[i] == f:
			e = 1
			break
	if e == 0:
		d += 1
print(d)


ll = lambda : list(map(int, input().split()))
testcases = 1
for testcase in range(testcases):
	[n] = ll()
	d = []
	opener = [0] * 1001
	for i in range(n):
		x = ll()
		opener[x[1]] += 1
		d.append(x)
	c = 0
	for i in range(n):
		opener[d[i][1]] -= 1
		if opener[d[i][0]] > 0:
			c += 1
		opener[d[i][1]] += 1
	print(n - c)


n = int(input())
openable = set()
not_openable = {}
for _ in range(n):
	(a, b) = map(int, input().split())
	if b in not_openable:
		not_openable[b] = 0
	if a not in openable:
		not_openable[a] = not_openable.get(a, 0) + 1
	openable.add(b)
print(sum(not_openable.values()))


c = 0
aa = []
bb = []
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	aa.append(a)
	bb.append(b)
for i in range(len(aa)):
	for j in range(len(bb)):
		if aa[i] == bb[j] and i != j:
			c += 1
			break
print(n - c)


n = int(input())
a = []
b = []
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
t = 0
for i in range(len(a)):
	if b.count(a[i]) <= (a[i] == b[i]):
		t += 1
print(t)


n = int(input())
nn = n
nnn = n
b = []
o = []
c = 0
while n > 0:
	n -= 1
	(bt, ot) = map(int, input().split())
	b.append(bt)
	o.append(ot)
for i in range(0, nnn):
	if b[i] == o[i] and o.count(o[i]) == 1:
		nn += 1
o = set(o)
for i in o:
	temp = b.count(i)
	nn -= temp
print(nn)


n = int(input())
t = [[int(x) for x in input().split(' ')] for _ in range(n)]
a = []
b = []
a = [t[i][0] for i in range(n)]
b = [t[i][1] for i in range(n)]
c = [0 for i in range(n)]
for i in range(len(b)):
	for j in range(len(c)):
		if b[i] == a[j] and i != j:
			c[j] = 1
h = 0
for i in c:
	if i == 0:
		h += 1
print(h)


from sys import stdin, stdout
input = stdin.readline
import math, bisect
n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
cnt = 0
for i in range(n):
	temp = l[i][1]
	for j in range(n):
		if i != j and l[j][0] != -1:
			if l[j][0] == temp:
				l[j][0] = -1
				cnt += 1
print(n - cnt)


n = int(input())
lst = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	lst.append((a, b))
ret = 0
for i in range(n):
	(a, b) = lst[i]
	for j in range(n):
		if i == j:
			continue
		(aa, bb) = lst[j]
		if bb == a:
			ret += 1
			break
print(n - ret)


def main():
	desc = set()
	brand = [0] * 1001
	proc = [0] * 1001
	tb = [False] * 1001
	n = int(input())
	total = n
	for i in range(n):
		(a, b) = map(int, input().split())
		desc.add(a)
		brand[a] += 1
		proc[b] += 1
		tb[b] |= True if a != b else False
	for a in desc:
		if tb[a] or proc[a] > 1:
			total -= brand[a]
		elif proc[a]:
			total -= brand[a] - 1
	print(total)
main()


n = int(input())
arr = []
brr = []
for _ in range(n):
	(a, b) = map(int, input().split())
	arr.append(a)
	brr.append(b)
cnt = 0
for i in range(0, n):
	if arr[i] not in brr:
		cnt += 1
	elif arr[i] == brr[i]:
		if brr.count(brr[i]) == 1:
			cnt += 1
print(cnt)


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	lis2 = []
	for i in range(n):
		lis = list(map(int, input.readline().split()))
		lis2.append([lis[0], lis[1], False])
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if lis2[j][0] == lis2[i][1]:
				lis2[j][2] = True
	count = 0
	for x in lis2:
		if x[2] == False:
			count += 1
	output = count
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


n = int(input())
(l, r) = ([], [])
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
for i in range(n):
	for j in range(n):
		if l[i] == r[j] and i != j:
			break
	else:
		ans += 1
print(ans)


n = int(input())
k = []
t = []
for i in range(n):
	(p, m) = map(int, input().split())
	k.append(p)
	t.append(m)
ans = n
for i in range(len(k)):
	for j in range(len(t)):
		if i == j:
			continue
		if k[i] == t[j]:
			ans -= 1
			break
print(ans)


n = int(input())
c = 0
a = []
b = []
x = [0] * 1001
for i in range(n):
	(w, e) = map(int, input().split())
	a.append(w)
	b.append(e)
	x[b[i]] += 1
for i in range(n):
	if x[a[i]] < 1 or (x[a[i]] == 1 and a[i] == b[i]):
		c += 1
print(c)


n = int(input())
bottles = {}
pairs = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	if a not in bottles:
		if a != b:
			bottles[a] = [1, 0]
		else:
			bottles[a] = [0, 1]
	elif a != b:
		bottles[a][0] += 1
	else:
		bottles[a][1] += 1
	pairs.append([a, b])
for b in pairs:
	if b[1] in bottles and bottles[b[1]][0] > 0:
		bottles[b[1]][0] = 0
	if b[1] in bottles and bottles[b[1]][1] == 1:
		if b[0] != b[1]:
			bottles[b[1]][1] = 0
answer = 0
for b in bottles:
	answer += bottles[b][0]
	if bottles[b][1] == 1:
		answer += 1
print(answer)


import sys, os, io, time, copy, math
from functools import lru_cache
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	n = int(input())
	arr = []
	for _ in range(n):
		(x, y) = map(int, input().split())
		arr.append([x, y, False])
	for i in range(n):
		op = arr[i][1]
		for j in range(n):
			if i != j and arr[j][0] == op:
				arr[j][2] = True
	count = 0
	for a in arr:
		if a[2] == False:
			count += 1
	print(count)
main()


n = int(input())
a = [None] * n
for i in range(n):
	a[i] = tuple(map(int, input().split()))
ans = 0
for (i, x) in enumerate(a):
	ok = 0
	for (j, y) in enumerate(a):
		if i == j:
			continue
		if y[1] == x[0]:
			ok = 1
	ans += ok ^ 1
print(ans)


a = int(input())
b = []
c = []
for _ in range(0, a):
	(x, y) = map(int, input().split())
	b.append(x)
	c.append(y)
sum = 0
for _ in range(0, a):
	flag = 0
	for index in range(0, a):
		if index != _ and b[_] == c[index]:
			flag = 1
	if flag == 0:
		sum = sum + 1
print(sum)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

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

def sip():
	return sys.stdin.readline()

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

def mips():
	return map(str, sys.stdin.readline().split())

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
t = ip()
bottles = []
opened = []
count = 0
for _ in range(t):
	(a, b) = mip()
	bottles.append(a)
	opened.append(b)
for i in range(t):
	if bottles[i] not in opened[:i]:
		if bottles[i] not in opened[i + 1:]:
			count += 1
print(count)


n = int(input())
arr_a = []
arr_b = []
arr_c = [0 for i in range(10001)]
for i in range(n):
	(a, b) = map(int, input().split())
	arr_a.append(a)
	arr_b.append(b)
	arr_c[b] += 1
count = 0
for i in range(n):
	arr_c[arr_b[i]] -= 1
	if arr_c[arr_a[i]] == 0:
		count += 1
	arr_c[arr_b[i]] += 1
print(count)


n = int(input())
x = []
y = []
z = []
for i in range(n):
	(a, b) = map(int, input().split())
	x.append(a)
	y.append(b)
for i in range(n):
	if x[i] not in y:
		z.append(x[i])
	elif x[i] in y and x[i] == y[i]:
		if y.count(x[i]) == 1:
			z.append(x[i])
print(len(z))


n = int(input())
(la, lb) = ([], [])
for _ in range(n):
	(a, b) = map(int, input().split())
	la.append(a)
	lb.append(b)
res = 0
for i in range(n):
	temp = la[i]
	if lb.count(temp) > 1:
		res += 1
	elif lb.count(temp) == 1 and lb.index(temp) != i:
		res += 1
print(n - res)


n = int(input())
count = 0
(arr_a, arr_b) = ([], [])
for _ in range(n):
	(a, b) = map(int, input().split(' '))
	arr_a.append(a)
	arr_b.append(b)
for i in range(n):
	for j in range(n):
		if arr_a[i] == arr_b[j] and i != j:
			count += 1
			break
print(n - count)


n = int(input())
(a, b) = ([0] * n, [0] * n)
for i in range(0, n):
	(a[i], b[i]) = map(int, input().split())
t = [0] * n
for i in range(n):
	t[i] = b[i]
s = 0
for i in range(0, n):
	b[i] = 0
	if a[i] in b:
		b[i] = t[i]
		continue
	else:
		s += 1
		b[i] = t[i]
print(s)


from collections import Counter
n = int(input())
(a, b) = ([], [])
for i in range(n):
	(a_i, b_i) = map(int, input().split())
	a.append(a_i)
	b.append(b_i)

def check(i):
	for j in range(n):
		if j != i and b[j] == a[i]:
			return True
	return False
unopened = 0
for i in range(n):
	if not check(i):
		unopened += 1
print(unopened)


n = int(input())
a = [0] * 1000
b = [0] * 1000
lst = [0] * 1001
for x in range(n):
	(a[x], b[x]) = map(int, input().split())
	lst[b[x]] += 1
ans = 0
for x in range(n):
	lst[b[x]] -= 1
	if lst[a[x]] == 0:
		ans += 1
	lst[b[x]] += 1
print(ans)


n = int(input())
a = []
b = []
x = []
for i in range(n):
	(c, d) = map(int, input().split())
	a.append(c)
	b.append(d)
for i in range(n):
	if a[i] in b:
		if b[i] == a[i]:
			if b.count(a[i]) > 1:
				n -= 1
		else:
			n -= 1
print(n)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
ans = n
for i in range(n):
	for j in range(n):
		if a[i] == b[j] and i != j:
			ans -= 1
			break
print(ans)


n = int(input())
O = [0] * n
B = list(O)
for i in range(n):
	(a, b) = map(int, input().split())
	O[i] = b
	B[i] = a
ans = n
for i in range(n):
	for j in range(n):
		if j == i:
			continue
		if O[j] == B[i]:
			ans -= 1
			break
print(ans)


n = int(input())
arr = []
brr = []
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append(a)
	brr.append(b)
for i in range(n):
	flag = 0
	for j in range(i):
		if brr[j] == arr[i]:
			flag = 1
			break
	if flag != 1:
		for k in range(i + 1, n):
			if brr[k] == arr[i]:
				flag = 1
				break
	if flag == 0:
		ans += 1
print(ans)


from itertools import product

def main():
	n = int(input())
	m = []
	beg = []
	for _ in range(n):
		x = list(map(int, input().split()))
		m.append(x)
		beg.append(x[0])
	ans = 0
	cur = []
	for j in m:
		if j[1] not in cur and j[1] in beg and (j[1] != j[0]):
			ans += beg.count(j[1])
			cur.append(j[1])
		elif j[1] not in cur and j[1] in beg and (j[1] == j[0]):
			ans += beg.count(j[1]) - 1
	if n - ans <= 0:
		return 0
	else:
		return n - ans
print(main())


from collections import defaultdict
n = int(input())
freq = defaultdict(int)
li = []
for i in range(n):
	(a, b) = map(int, input().split())
	li.append([a, b])
	freq[a] += 1
for i in range(n):
	for j in range(n):
		if i != j:
			if li[j][0] == li[i][1]:
				freq[li[j][0]] = max(freq[li[j][0]] - 1, 0)
res = 0
for i in freq:
	res += freq[i]
print(res)


def main():
	n = int(input())
	t = n
	A = []
	B = []
	while t > 0:
		(a, b) = map(int, input().split())
		A.append(a)
		B.append(b)
		t = t - 1
	x = 0
	for u in range(n):
		for v in range(n):
			if A[u] == B[v] and u != v:
				x = x + 1
				break
	print(n - x)
main()


n = int(input())
a = []
b = []
c = [0] * 1001
for i in range(n):
	(x, y) = list(map(int, input().strip().split()))
	a.append(x)
	b.append(y)
	c[y] += 1
count = 0
for i in range(n):
	c[b[i]] -= 1
	if c[a[i]] == 0:
		count += 1
	c[b[i]] += 1
print(count)


n = int(input())
count = 0
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
v = b.copy()
for i in range(n):
	del v[i]
	if not a[i] in v:
		count += 1
	v = b.copy()
print(count)


n = int(input())
key = []
value = []
for _ in range(n):
	(a, b) = input().split()
	key.append(a)
	value.append(b)
count = 0
for i in range(n):
	a = key[i]
	if a in value:
		if key[i] == value[i] and value.count(value[i]) < 2:
			count += 1
	else:
		count += 1
print(count)


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
ok = [False] * n
for i in range(n):
	for j in range(n):
		if b[i] == a[j] and i != j:
			ok[j] = True
print(ok.count(False))


n = int(input())
l_arr = []
r_arr = []
for _ in range(n):
	(l, r) = map(int, input().split())
	l_arr.append(l)
	r_arr.append(r)
count = 0
for i in range(n):
	if l_arr[i] not in r_arr[:i] + r_arr[i + 1:]:
		count += 1
print(count)


n = int(input())
bottle = []
for i in range(n):
	bottle.append(list(map(int, input().split())))
count = 0
check = []
for i in range(n):
	check.append(False)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif bottle[i][1] == bottle[j][0] and check[j] == False:
			count += 1
			check[j] = True
print(n - count)


t = int(input())
p = []
q = []
r = 0
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	p.append(a)
	q.append(b)
for i in range(t):
	if p[i] not in q:
		r = r + 1
	elif q.count(p[i]) == 1 and q.index(p[i]) == i:
		r = r + 1
print(r)


n = int(input())
(a, b) = ([], [])
for i in range(n):
	(l, m) = input().split()
	a.append(int(l))
	b.append(int(m))
count = 0
for i in range(n):
	for j in range(n):
		if b[j] == a[i] and i != j:
			count += 1
			break
print(n - count)


n = int(input())
a = []
for _ in range(n):
	(x, y) = [int(x) for x in input().split()]
	a.append((x, y))
openable = 0
for (x, (i, j)) in enumerate(a):
	for (y, (l, m)) in enumerate(a):
		if i == m and x != y:
			openable += 1
			break
print(n - openable)


n = int(input())
a = []
b = []
for i in range(n):
	li = list(map(int, input().split()))
	a.append(li[0])
	b.append(li[1])
count = 0
for idx1 in range(len(a)):
	flag = False
	for idx2 in range(len(b)):
		if idx1 != idx2 and a[idx1] == b[idx2]:
			flag = True
	if not flag:
		count += 1
print(count)


n = int(input())
(a, b) = ([], [])
cnt = 0
for i in range(n):
	(a1, b1) = input().split()
	(a1, b1) = (int(a1), int(b1))
	a.append(a1)
	b.append(b1)
for i in range(n):
	for j in range(n):
		if i != j and a[i] == b[j]:
			cnt += 1
			break
print(n - cnt)


n = int(input())
a = []
b = []
count = 0
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
dct = [False for x in a]
for i in range(n):
	for j in range(n):
		if j != i and b[j] == a[i]:
			dct[i] = True
for num in dct:
	if not num:
		count += 1
print(count)


n = int(input())
d = {}
a = []
b = []
for _ in range(n):
	(i, j) = map(int, input().split())
	a.append([i, j])
	b.append([i, 0])
for p in range(n):
	pair = a[p]
	for i in range(n):
		if i != p:
			if pair[1] == a[i][0]:
				b[i][1] = 1
c = 0
for i in b:
	if i[1] == 0:
		c += 1
print(c)


n = int(input())
b = []
c = []
for _ in range(n):
	(x, y) = map(int, input().split())
	b.append(x)
	c.append(y)
res = 0
for i in range(n):
	if b[i] in c[:i] or b[i] in c[i + 1:]:
		res += 1
print(n - res)


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
n = iinput()
x = []
y = []
count = 0
for i in range(n):
	(a, b) = rinput()
	x.append(a)
	y.append(b)
for i in range(n):
	flag = True
	for j in range(n):
		if i != j:
			if x[i] == y[j]:
				flag = False
	if flag == True:
		count += 1
print(count)


n = int(input())
brand = []
opener = []
for s in range(n):
	(a, b) = map(int, input().split())
	brand.append(a)
	opener.append(b)
for i in range(len(brand)):
	if n == 0:
		break
	for j in range(len(opener)):
		if n == 0:
			break
		if i != j:
			if brand[i] == opener[j]:
				n -= 1
				break
print(n)


from collections import defaultdict
n = int(input())
l = []
d = defaultdict(int)
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
	d[b] += 1
for i in range(n):
	if l[i][1] == l[i][0] and d[l[i][1]] == 1 or l[i][0] not in d:
		ans += 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
ans = 0
l = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	temp = 0
	for j in range(n):
		if l[i][0] == l[j][1] and i != j:
			temp += 1
	if temp == 0:
		ans += 1
print(ans)


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mi = lambda : map(int, input().split())
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
mati = lambda r: [li() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def solve():
	n = ii()
	arr1 = []
	arr2 = []
	for x in range(n):
		(a, b) = mi()
		arr1.append(a)
		arr2.append(b)
	ans = 0
	for x in range(len(arr1)):
		if arr1[x] not in arr2[:x] and arr1[x] not in arr2[x + 1:]:
			ans += 1
	print(ans)
for _ in range(1):
	solve()


n = int(input())
a = []
b = []
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
total = n
for i in range(n):
	for j in range(n):
		if i != j and a[i] == b[j]:
			total -= 1
			break
print(total)


n = int(input())
a = []
b = []
c = [1] * n
for i in range(n):
	q = input().split()
	a.append(q[0])
	b.append(q[1])
for i in range(n):
	for j in range(n):
		if a[j] == b[i] and i != j:
			c[j] = 0
print(sum(c))


N = int(input())
bottles = set()
arr = []
arr2 = []
for i in range(N):
	(index, b) = map(int, input().split())
	arr.append(index)
	arr2.append(b)
cnt = 0
for i in range(N):
	for j in range(N):
		if arr[i] == arr2[j] and i != j:
			cnt += 1
			break
print(N - cnt)


import re
in1 = int(input())
count = 0
bto = []
bco = []
conA = []
conB = []
for _ in range(in1):
	inX = [int(x) for x in re.split('\\s', input())]
	if inX[0] != inX[1]:
		bto.append(inX[0])
		bco.append(inX[1])
	elif inX[0] not in conA:
		conA.append(inX[1])
	else:
		conB.append(inX[1])
for x in conA:
	if x not in conB and x not in bco:
		count += 1
for x in bto:
	if x not in bco and x not in conA:
		count += 1
print(count)


import sys
import math
n = int(sys.stdin.readline())
k = [0] * 1001
l = []
for i in range(n):
	(a, b) = [int(x) for x in sys.stdin.readline().split()]
	k[b] += 1
	l.append((a, b))
res = 0
for i in l:
	if i[0] == i[1] and k[i[0]] == 1:
		res += 1
	if k[i[0]] == 0:
		res += 1
print(res)


import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	a = []
	for i in range(n):
		a.append(intl())
	ans = 0
	for i in range(n):
		f = False
		for j in range(n):
			if i == j:
				continue
			elif a[i][0] == a[j][1]:
				f = True
		if f:
			ans += 1
	print(n - ans)
start_time = time.time()
solve()


from math import floor

def main():
	z = []
	bottles = []
	for i in range(int(input())):
		(x, y) = map(int, input().split())
		bottles.append((x, i))
		z.append((y, i))
	for j in range(len(z)):
		k = 0
		for f in range(len(bottles)):
			f -= k
			if z[j][0] == bottles[f][0] and z[j][1] != bottles[f][1]:
				bottles.pop(f)
				k += 1
	print(len(bottles))
main()


n = int(input())
res = [[0, False, 0] for k in range(1000)]
for i in range(n):
	(a, b) = list(map(int, input().split()))
	res[a - 1][0] += 1
	if a != b:
		res[b - 1][1] = True
	else:
		res[b - 1][2] += 1
ans = 0
for el in res:
	if not el[1]:
		if el[2] == 0:
			ans += el[0]
		elif el[2] == 1:
			ans += 1
print(ans)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
from fractions import Fraction
l = []
l1 = []
for i in range(ii()):
	(a, b) = mi()
	l.append(b)
	l1.append(a)
c = 0
for i in range(len(l)):
	if l.count(l1[i]) > 1 or (l.count(l1[i]) == 1 and l[i] != l1[i]):
		c += 1
print(len(l) - c)


n = int(input())
t = 0
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().rstrip().split())
	a += [x]
	b += [y]
for i in range(n):
	x = a[i]
	if x not in b or (b[i] == x and b.count(x) == 1):
		t += 1
print(t)


n = int(input())
count = 0
a = [0] * n
b = [0] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
for i in range(n):
	for j in range(n):
		if a[i] == b[j] and j != i:
			count += 1
			break
print(n - count)


n = int(input())
a = [0] * n
b = [0] * n
c = 0
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if b[i] == a[j]:
			a[j] = 0
for i in a:
	if i == 0:
		c += 1
print(n - c)


def spliter():
	d = input()
	a = d.split()
	r = []
	for i in a:
		k = int(i)
		r.append(k)
	return r
n = spliter()
lst1 = []
lst2 = []
count = []
for i in range(n[0]):
	a = spliter()
	lst1.append(a[1])
	lst2.append(a[0])
for i in range(n[0]):
	for j in range(n[0]):
		if i != j:
			if lst1[i] == lst2[j]:
				count.append(lst2[j])
				lst2[j] = 0
print(len(lst2) - len(count))


n = int(input())
bs = []
for _ in range(n):
	bs.append(list(map(int, input().split())))
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and bs[i][0] == bs[j][1]:
			ans += 1
			break
print(n - ans)


import sys
input = sys.stdin.readline

def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
MOD = '1000000007'
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
n = gint()
res = n
inp = []
opened = [False] * n
for i in range(n):
	inp.append(gint_arr())
i = 0
while i < n:
	j = 0
	while j < n:
		if i == j:
			j += 1
			continue
		if inp[j][0] == inp[i][1] and (not opened[j]):
			res -= 1
			opened[j] += 1
		j += 1
	i += 1
print(res)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
n = ii()
(a, b) = ([], [])
for i in range(n):
	(ta, tb) = mi()
	a.append(ta)
	b.append(tb)
ans = 0
for i in range(n):
	if a[i] not in b or (b.count(a[i]) == 1 and b[i] == a[i]):
		ans += 1
print(ans)


n = int(input())
a = []
b = []
freq = {}
for i in range(n):
	(ai, bi) = [int(x) for x in input().split()]
	a.append(ai)
	b.append(bi)
	if bi not in freq:
		freq[bi] = 0
	freq[bi] += 1
ans = n
for i in range(n):
	if a[i] not in freq or freq[a[i]] == 0:
		continue
	if freq[a[i]] == 1 and b[i] == a[i]:
		continue
	ans -= 1
print(ans)


n = int(input())
bottles = [list(map(int, input().split())) for i in range(n)]
opened = set()
for i in range(n):
	for j in range(n):
		if i != j and bottles[i][1] == bottles[j][0]:
			opened.add(j)
print(n - len(opened))


n = int(input())
l = [0] * n
r = [0] * n
num = [0] * 10000
for i in range(n):
	(l[i], r[i]) = list(map(int, input().split()))
	num[r[i]] += 1
ans = n
for i in range(n):
	if num[l[i]] == 1 and l[i] == r[i]:
		continue
	if num[l[i]] < 1:
		continue
	ans -= 1
print(ans)


l1 = []
l2 = []
n = int(input())
for _ in range(n):
	(x, y) = list(map(int, input().split()))
	l1.append(x)
	l2.append(y)
ans = [1] * n
for i in range(len(l1)):
	for j in range(len(l2)):
		if i == j:
			continue
		if l2[i] == l1[j]:
			ans[j] = 0
print(sum(ans))


n = int(input())
(bottles, openers) = ([], [])
for _ in range(n):
	(a, b) = map(int, input().split())
	openers.append(b)
	bottles.append(a)
opened = [False] * n
for i in range(n):
	for j in range(n):
		if i != j and openers[i] == bottles[j] and (not opened[j]):
			opened[j] = True
count = 0
for i in range(n):
	if not opened[i]:
		count += 1
print(count)


n = int(input())
l1 = list()
l2 = list()
l = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
for i in range(n):
	if l1[i] in l2[:i] or l1[i] in l2[i + 1:]:
		l = l + 1
print(n - l)


n = int(input())
A = []
for i in range(n):
	A.append(list(map(int, input().split())))
res = 0
for i in range(n):
	flag = 0
	for j in range(n):
		if A[j][1] == A[i][0] and i != j:
			flag = 1
	res += 1 - flag
print(res)


def main():
	(n, aa, bb) = (int(input()), [], [])
	for _ in range(n):
		(a, b) = input().split()
		aa.append(a)
		bb.append(b)
	print(n - len({i for (i, a) in enumerate(aa) for (j, b) in enumerate(bb) if i != j and a == b}))
main()


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

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
N = inp()
S = set()
M = set()
D = dict()
A = []
B = []
for n in range(N):
	(x, y) = invr()
	if x != y:
		S.add(y)
	elif x not in M:
		M.add(x)
	else:
		S.add(x)
	if x not in D:
		D[x] = 1
	else:
		D[x] += 1
	A.append(x)
	B.append(y)
out = 0
for a in range(len(A)):
	if A[a] not in S and (A[a] not in M or A[a] == B[a]):
		out += 1
print(out)


from collections import defaultdict
n = int(input())
isOpened = defaultdict(bool)
count = defaultdict(int)
whoCanWe = defaultdict(list)
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	count[a] += 1
	isOpened[a] = False
	whoCanWe[a].append(b)
opend = 0
flag = 0
for i in whoCanWe:
	for j in whoCanWe[i]:
		if i != j:
			if count[j]:
				opend += count[j]
				count[j] = 0
				isOpened[j] = True
		elif i == j and count[i] > 1:
			opend += count[j] - 1
			count[j] = 1
			flag = 1
		elif i == j and count[i] == 1:
			if flag == 1:
				flag = 0
				count[j] = 0
				opend += 1
print(n - opend)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	if n == 1:
		return 1
	cnt = 2
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != n // i:
				cnt += 2
			else:
				cnt += 1
	return cnt

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	n = ii()
	d = defaultdict(int)
	brnd = []
	for i in range(n):
		(x, y) = mi()
		brnd.append((x, y))
	cnt = n
	for i in range(n):
		for j in range(n):
			if i != j:
				if brnd[j][1] == brnd[i][0]:
					cnt -= 1
					break
	print(cnt)
main()


n = int(input())
a = []
b = []
for i in range(n):
	(aa, bb) = map(int, input().split())
	a.append(aa)
	b.append(bb)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if a[j] == b[i]:
			a[j] = -1
count = 0
for i in range(n):
	if a[i] != -1:
		count += 1
print(count)


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
ans = 0
opened = set()
for i in range(n):
	for j in range(n):
		if a[i] == b[j] and i != j:
			ans += 1
			break
print(len(a) - ans)


n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
res = 0
for i in range(n):
	valid = 0
	for j in range(n):
		if arr[j][1] == arr[i][0] and i != j:
			valid = 1
	res += 1 - valid
print(res)


c = 0
u = []
o = []
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	u.append(a)
	o.append(b)
for i in range(len(o)):
	for j in range(len(u)):
		if o[i] == u[j] and i != j:
			c += 1
			u[j] = 0
print(n - c)


n = int(input())
size = n + 1
bottle_num = [0] * size
left_arr = []
right_arr = []
for i in range(n):
	ab_list = list(map(int, input().split()))
	if len(left_arr) == 0:
		left_arr.append(0)
	if len(right_arr) == 0:
		right_arr.append(0)
	left_arr.append(ab_list[0])
	right_arr.append(ab_list[1])
for j in range(1, n + 1):
	for k in range(1, n + 1):
		if j != k and left_arr[j] == right_arr[k]:
			bottle_num[j] = 1
total = 0
for i in range(1, n + 1):
	total += bottle_num[i]
print(n - total)


n = int(input())
a = [0] * n
b = [0] * n
s = [0] * n
ans = 0
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
for p in range(n):
	for j in range(n):
		if p != j and a[j] == b[p]:
			if s[j] == 0:
				s[j] = 1
for t in range(n):
	ans += s[t]
print(n - ans)


n = int(input())
d = {}
A = [0 for i in range(n)]
B = [0 for i in range(n)]
for i in range(n):
	(a, b) = map(int, input().split())
	if b not in d:
		d[b] = 0
	d[b] += 1
	A[i] = a
	B[i] = b
count = 0
for i in range(n):
	if A[i] not in d or (d[A[i]] == 1 and A[i] == B[i]):
		count += 1
print(count)


a = int(input())
arr = []
brr = []
for i in range(0, a):
	(x, y) = map(int, input().split())
	arr.append(x)
	brr.append(y)
flag = False
counter = 0
for i in range(0, a):
	flag = False
	for j in range(0, a):
		if i == j:
			continue
		if arr[i] == brr[j]:
			flag = True
			break
	if flag == False:
		counter += 1
print(counter)


n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
c = 0
for i in range(n):
	temp = 0
	for j in range(n):
		if l[i][0] == l[j][1] and i != j:
			temp += 1
	if temp == 0:
		c += 1
print(c)


n = int(input())
(a, b) = zip(*[map(int, input().split()) for _ in range(n)])
print(sum([b.count(a[i]) <= (a[i] == b[i]) for i in range(n)]))


def chc(l, i, k):
	for j in range(len(l)):
		if k == l[j] and j != i:
			return 1
	return 0
n = int(input())
(b, o) = ([], [])
c = 0
for i in range(n):
	(l, r) = map(int, input().split())
	b.append(l)
	o.append(r)
for i in range(n):
	if chc(o, i, b[i]):
		c += 1
print(n - c)


a = int(input())
bad = []
for i in range(a):
	(x, y) = map(int, input().split(' '))
	bad.append([x, y, 0])
for i in range(a):
	for j in range(a):
		if i != j:
			if bad[j][1] == bad[i][0]:
				bad[i][2] = 1
ct = 0
for i in bad:
	if i[2] == 1:
		ct += 1
print(a - ct)


n = int(input())
a = []
b = []
for x in range(0, n):
	l = list(map(int, input().split(' ')))
	a.append(l)
	b.append(l[1])
c = 0
for (x, y) in a:
	if x == y and b.count(x) == 1:
		c += 1
	elif x in b:
		pass
	else:
		c += 1
print(c)


n = int(input())
cnt = [0] * 1001
s = [0] * 1001
ina = []
inb = []
for i in range(n):
	(a, b) = map(int, input().split())
	ina.append(a)
	inb.append(b)
	cnt[a - 1] += 1
	if a != b:
		s[b - 1] = 1
ans = 0
for i in range(n):
	(a, b) = (ina[i], inb[i])
	if cnt[a - 1] > 1 and a == b:
		s[b - 1] = 1
	if cnt[a - 1] > 1 and a == b and (inb.count(a) == 1):
		ans = -1
for i in range(1001):
	ans += cnt[i] * s[i]
print(n - ans)


n = int(input())
bottles = [0] * 1001
types = [0] * 1001
for i in range(n):
	(a, b) = map(int, input().split())
	bottles[a] += 1
	if a == b and types[a] == 0:
		types[a] = -1
	else:
		types[b] = max(types[b] + 1, -types[b] + 1)
print(n - sum((bottles[i] if types[i] > 0 else -types[i] * (bottles[i] - 1) for i in range(1001))))


from sys import stdin, stdout
import math
import bisect
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	n = int(input())
	a = []
	b = []
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append(x)
		b.append(y)
	cnt = 0
	for i in range(n):
		flag = 0
		for j in range(n):
			if i == j:
				continue
			if b[j] == a[i]:
				flag = 1
				break
		if not flag:
			cnt += 1
	print(cnt)
tt = 1
for __ in range(tt):
	solve()


n = int(input())
arr = []
for l in range(n):
	arr.append(list(map(int, input().split())))
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and arr[i][0] == arr[j][1]:
			ans += 1
			break
print(n - ans)


n = int(input())
(m, p) = ([], [])
for i in ' ' * n:
	(a, b) = list(map(int, input().split()))
	m.append(a)
	p.append(b)
for (i, j) in zip(m, p):
	if i != j and i in p or (i == j and p.count(i) > 1):
		n = n - 1
print(n)


(l, q, r) = ([0] * 1001, 0, [])
for i in [*open(0)][1:]:
	(b, a) = map(int, i.split())
	l[a] += 1
	r += [[a, b]]
for i in r:
	if l[i[1]] == 0 or (i[0] == i[1] and l[i[1]] == 1):
		q += 1
print(q)


n = int(input())
L = []
for i in range(n):
	l = list(input().split())
	for j in range(2):
		l[j] = int(l[j])
	L.append(l)
ans = 0
for i in range(n):
	exist = False
	for j in range(n):
		if L[i][0] == L[j][1] and i != j:
			exist = True
			break
	if not exist:
		ans += 1
print(ans)


t = int(input())
a = list()
b = list()
for i in range(t):
	c = list(map(int, input().strip().split(' ')))
	a.append(c[0])
	b.append(c[1])
flag = 0
count = 0
for i in range(t):
	for j in range(t):
		if a[i] == b[j] and i != j:
			flag = 1
			break
	if flag == 0:
		count += 1
	flag = 0
print(count)


import os
import sys
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def divisors(n):
	i = 1
	div = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				div.append(i)
			else:
				div.append(i)
				div.append(n // i)
		i = i + 1
	return div

def solve():
	n = int(input())
	pairs = []
	for i in range(n):
		(a, b) = map(int, input().split())
		pairs.append([a, b])
	cnt = 0
	for i in range(n):
		typee = pairs[i][0]
		flag = 0
		for j in range(n):
			if j != i:
				if pairs[j][1] == typee:
					flag = 1
					break
		if flag == 0:
			cnt = cnt + 1
	print(cnt)

def main():
	solve()
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l1 = []
l = []
c = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l.append(b)
for i in range(len(l1)):
	if l1[i] not in l[:i] and l1[i] not in l[i + 1:]:
		c += 1
print(c)


def bottle(n):
	arr = []
	count = 0
	for i in range(n):
		arr.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(n):
			if j != i:
				if arr[j][1] == arr[i][0]:
					break
		else:
			count += 1
	print(count)
bottle(int(input()))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def convert_check(num, base):
	base_rev = ''
	if num == 0:
		base_rev = '0'
	while num > 0:
		r = num % base
		if r > 1:
			return 'NO'
		num = num // base
		base_rev += str(r)
	return base_rev[::-1]
n = int(input())
a = []
b = []
c = [1] * n
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
for i in range(n):
	for j in range(n):
		if a[j] == b[i] and i != j:
			c[j] = 0
print(sum(c))


from sys import stdin
n = int(stdin.readline())
a = [-1] * n
b = [-1] * n
opened = [0] * n
for i in range(n):
	(a_, b_) = [int(v) for v in stdin.readline().split()]
	a[i] = a_
	b[i] = b_
o1 = [-1] * 1001
o2 = [-1] * 1001
for i in range(n):
	if o1[b[i]] != -1:
		o2[b[i]] = i
	else:
		o1[b[i]] = i
sol = 0
for i in range(n):
	if o1[a[i]] == -1 or (o1[a[i]] == i and o2[a[i]] == -1):
		sol += 1
print(sol)


import sys
num = int(sys.stdin.readline())
(arr_a, arr_b) = ([], [])
cnt = 0
for i in range(num):
	(a, b) = map(int, sys.stdin.readline().split())
	arr_a.append(a)
	arr_b.append(b)
for i in range(num):
	for j in range(num):
		if i != j and arr_a[i] == arr_b[j]:
			cnt += 1
			break
sys.stdout.write(str(num - cnt))


def main():
	n = int(input())
	a = []
	b = []
	opened = [0] * 1001
	for i in range(n):
		(ai, bi) = map(int, input().split())
		a.append(ai)
		b.append(bi)
	answer = 0
	for i in range(n):
		opened[b[i]] += 1
	for i in range(n):
		opened[b[i]] -= 1
		if opened[a[i]] == 0:
			answer += 1
		opened[b[i]] += 1
	print(answer)
main()


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
t = set()
for i in range(n):
	for j in range(n):
		if i != j and a[i][1] == a[j][0]:
			t.add(j)
print(n - len(t))


n = int(input())
(s1, s2) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	s1 += [a]
	s2 += [b]
c = 0
for i in range(n):
	for j in range(n):
		if s1[i] == s2[j] and i != j:
			c += 1
			break
print(n - c)


n = int(input())
A = []
B = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	A.append(a)
	B.append(b)
count = [1] * n
vis = set()
for i in range(n):
	for j in range(n):
		if B[i] == A[j] and i != j:
			count[j] = 0
print(sum(count))


get = lambda : list(map(int, input().split()))
n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = get()
	a.append(x)
	b.append(y)
d = n
for i in range(n):
	for j in range(n):
		if a[i] == b[j] and i != j:
			d -= 1
			break
print(d)


n = int(input())
d = [0] * 1001
d1 = [0] * 1001
L = [list(map(int, input().split())) for i in range(n)]
for x in L:
	if x[0] == x[1]:
		d[x[1]] += 0.5
	else:
		d[x[1]] = 1
	d1[x[0]] += 1
k = 0
for i in range(1, 1001):
	if d[i] == 0:
		k += d1[i]
	if d[i] == 0.5:
		k += 1
print(k)


from collections import defaultdict as ddict
N = int(input())
count = ddict(int)
bottles = []
for i in range(N):
	(ai, bi) = map(int, input().split())
	count[bi] += 1
	bottles.append((ai, bi))
res = 0
for (ai, bi) in bottles:
	if count[ai] == 0 or (count[ai] == 1 and bi == ai):
		res += 1
print(res)


n = int(input())
e = 0
a = []
b = [[] for i in range(1001)]
for i in range(n):
	(s, t) = map(int, input().split())
	a.append([i, s])
	b[t].append(i)
for i in range(len(a)):
	c1 = 0
	for j in range(len(b[a[i][1]])):
		if b[a[i][1]][j] != i:
			c1 = -1
	if c1 != -1:
		e = e + 1
print(e)


n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	l.append([a, b])
ans = 0
for i in range(n):
	o = 0
	for j in range(n):
		if i == j:
			continue
		if l[j][1] == l[i][0]:
			o = 1
	if not o:
		ans += 1
print(ans)


n = int(input())
a = []
for i in range(n):
	b = list(map(int, input().split()))
	a.append(b)
d = []
t = 0
for i in a:
	d.append(i[1])
t = 0
for i in a:
	if i[0] == i[1]:
		if d.count(i[0]) == 1:
			t += 1
	elif i[0] not in d:
		t += 1
print(t)


n = int(input())
arr = [False] * n
des = []
for i in range(n):
	(a, b) = map(int, input().split())
	des.append([a, b, False])
for i in range(n):
	open = des[i][1]
	for j in range(n):
		if j != i:
			if des[j][0] == open:
				des[j][2] = True
count = 0
for i in des:
	if not i[2]:
		count += 1
print(count)


n = int(input())
a = []
b = []
for i in range(n):
	(aa, bb) = map(int, input().split())
	a.append(aa)
	b.append(bb)
ans = 0
for i in range(n):
	ne = 0
	for j in range(n):
		if i == j:
			continue
		elif b[j] == a[i]:
			ne = 1
	if ne == 0:
		ans += 1
print(ans)


from collections import defaultdict
n = int(input())
a = []
b = []
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
s = set()
for i in range(n):
	for j in range(n):
		if b[j] == a[i] and i != j:
			s.add(i)
print(n - len(s))


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
(l1, l2) = ([], [])
lvis = [1] * n
for _ in range(n):
	(a, b) = f()
	l1.append(a)
	l2.append(b)
for i in range(n):
	for j in range(n):
		if l2[i] == l1[j] and i != j:
			lvis[j] = 0
print(sum(lvis))


import collections
n = int(input())
A = [0] * 1010
A[0] = 1
B = []
C = []
E = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a != b:
		A[b] = 1
		E.append(a)
	else:
		C.append(a)
cnt = 0
D = collections.Counter(C)
for i in D.keys():
	if A[i] == 0:
		if D[i] >= 2:
			A[i] = 1
		elif i in E:
			A[i] = 1
			cnt += 1
for i in E + C:
	if A[i]:
		pass
	else:
		cnt += 1
print(cnt)