program officer;
var
a:array[0..10000]of longint;
c:array[1..10000]of boolean;
i:longint;
n:longint;
ans:int64;
procedure suan(x:longint);
var
o,p:int64;
begin
p:=ans*x;
o:=ans mod x;
while o<>0 do
begin
ans:=x;
x:=o;
o:=ans mod x;
end;
ans:=p div x;
end;
procedure search(const x,y:longint);
begin
if x=i then
begin
suan(y);
end
else
begin
c[x]:=true;
search(a[x],y+1);
end;
end;
begin
assign(input,'officer.in');
reset(input);
assign(output,'officer.out');
rewrite(output);
readln(n);
for i:=1 to n do
readln(a[i]);
ans:=1;
for i:=1 to n do
if c[i]=false then
search(a[i],1);
writeln(ans);
close(input);
close(output);
end.