var
f:array[0..200000]of longint;
x,i,j,ans,y:longint;
function fa(x:longint):longint;
begin
if f[x]=x then exit(x);
f[x]:=fa(f[x]);
fa:=f[x];
end;
begin
assign(input,'explosion.in'); reset(input);
assign(output,'explosion.out'); rewrite(output);
for i:=1 to 200000 do f[i]:=i;
read(x);
while x<>-1 do
begin
readln(y);
inc(x);
inc(y);
if fa(x)=fa(y) then inc(ans)
else begin
i:=fa(x);
j:=fa(y);
f[j]:=i;
end;
read(x);
end;
writeln(ans);
close(input);
close(output);
end.