program pie;
type
ee=record
a,b,c,d:integer;
end;
var
f1,f2:text;
sum,n,i,j,h:integer;
k:array[1..1000]of ee;
s:array[1..1000,1..1000]of boolean;
begin
assign(f1,'pie.in');
assign(f2,'pie.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:= 1to n do readln(f1,k[i].a,k[i].b);
fillchar(s,sizeof(s),0);
for i:=1 to n do
for j:= 1to n do
if (k[j].a=k[i].b)and(not s[i,j]) then begin inc(k[j].d);inc(k[i].c);s[j,i]:=true;end;
h:=0;
for i:= 1 to n do begin
if k[i].c=0 then begin inc(h);end;
end;
sum:=n+h;
writeln(f2,sum);
close(f1);
close(f2);
end.