program officer;
var
n,i,j,m,l,r:longint;
a,b,c:array[1..10000] of longint;
begin
assign(input,'officer.in');
assign(output,'officer.out');
reset(input);
rewrite(output);
readln(n);
l:=1;
for i:=1 to n do readln(a[i]);
for i:=1 to n do b[i]:=a[i];
for i:=1 to n do
begin
if b[i]<>b[b[i]] then
begin
c[l]:=b[b[i]];
l:=l+1;
b[b[i]]:=b[i];
m:=m+1;
end;
end;
r:=1;
i:=1;
while (i<l+r) and (c[i]<>0) do
begin
if b[b[c[i]]]=b[c[i]]
then
begin
b[c[i]]:=c[i];
i:=i+1;
m:=m+1;
end
else
begin
c[l+r]:=b[c[i]];
b[c[i]]:=c[i];
r:=r+1;
i:=i+1;
m:=m+1;
end;
end;
writeln(m-1);
close(input);
close(output);
end.