var
fa:array[0..100011] of longint;
i,j,m,n,x,y,ans:longint;
function get(v:longint):longint;
begin
if fa[v]=-1 then get:=v else
begin
fa[v]:=get(fa[v]);
get:=fa[v];
end;
end;
procedure he(x,y:longint);
var i,j:longint;
begin
i:=get(x);
j:=get(y);
fa[i]:=j;
end;
begin
assign(input,'explosion.in');reset(input);
assign(output,'explosion.out');rewrite(output);
fillchar(fa,sizeof(fa),$ff);
repeat
read(x);
if x=-1 then break;
readln(y);
if get(x)<>get(y) then
begin
he(x,y);
end else inc(ans);
until false;
writeln(ans);
close(input);close(output);
end.