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