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