program pie;
var
fin,fout:text;
n,i,t0,ans,a,b:longint;
v1:array[1..1000]of boolean;
v2:array[1..1000]of boolean;
begin
assign(fin,'pie.in'); reset(fin);
assign(fout,'pie.out'); rewrite(fout);
read(fin,n);
for i:=1 to 1000 do begin v1[i]:=false; v2[i]:=false; end;
ans:=0;
for i:=1 to n do
begin
read(fin,a,b);
t0:=0;
if v2[a] then begin v2[a]:=false; inc(t0); end;
if v1[b] then begin v1[b]:=false; inc(t0); end;
if t0=2 then
begin
dec(t0);
v1[a]:=true;
v2[a]:=true;
end;
inc(ans,t0);
end;
writeln(fout,n*2-ans);
close(fout);
end.