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: interview

Starter code:

Solutions:
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)


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)


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)


n = int(input())
a = [0] * n
b = [0] * n
ans = 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 and b[j] == a[i]:
      break
  else:
    ans += 1
print(ans)

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)

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)

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)

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())
a = []
b = []
for i in range(n):
    aa, bb = list(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, 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)))

def main():
    n = int (input())
    t = n;
    A = []
    B = []
    while ( t > 0):
        a,b = list(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)
            
def __starting_point():
    main()


__starting_point()

n=int(input())
O=[0]*n
B=list(O)
for i in range(n):
    a,b=list(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())
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
        else:
            if bottle[i][1] == bottle[j][0] and check[j] == False:
                count += 1
                check[j] = True
            
print(n-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)


a = int(input())
bad = []
for i in range(a):
    x, y = list(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())
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)

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)

def main():
    mode="filee"
    if mode=="file":f=open("test.txt","r")
    #f.readline()
    #input()
    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()


def __starting_point():
    main()

__starting_point()

def mainn():
    mode="filee"
    if mode=="file":f=open("test.txt","r")
    #f.readline()
    #input()
    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(0,count))
    
    if mode=="file":f.close()

def __starting_point():
    mainn()

__starting_point()

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}))


def __starting_point():
    main()

__starting_point()

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))


"""
	Author		: Arif Ahmad
	Date  		: 
	Algo  		: 
	Difficulty	: 
"""

def main():
	n = int(input())
	
	a = [None] * n
	b = [None] * n
	for i in range(n):
		a[i], b[i] = list(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)


def __starting_point():
    main()
    

__starting_point()

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)

from collections import defaultdict

def serej(bottles):
    #set of bottles that need to be opened

    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 list(unopened.values()))

n = int(input())

bottles = []
for _ in range(n):
    bottles.append([int(x) for x in input().split(' ')])

print(serej(bottles))


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)