program explosion;
const maxn=100001;
var
x,ans,i,y:longint;
fa:array[0..maxn] of longint;
function sf(k:longint):longint;
begin
if fa[k]<>k then fa[k]:=sf(fa[k]) else exit(K);
sf:=fa[k];
end;
begin
assign(input,'explosion.in'); reset(input);
assign(output,'explosion.out'); rewrite(output);
for i:=1 to maxn do fa[i]:=i;
read(x);
while x<>-1 do
begin
read(y);
if sf(x)<>sf(y) then
fa[sf(x)]:=sf(y) else
ans:=ans+1;
read(x);
end;
writeln(ans);
close(input); close(output);
end.