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