program gls;
var n,k,a:longint;p,max,ma:int64;
ss:array[1..10000]of longint;
st:array[1..10000]of boolean;
f,g:text;
function swapp(w:int64):int64;
begin
if st[w] then
begin
st[w]:=false;
exit(swapp(ss[w])+1);
end else exit(0);
end;
function gcd(a,b:int64):int64;
var
t:int64;
begin
while a mod b <> 0 do
begin
t:=a mod b;
a:=b;
b:=t;
end;
gcd:=b;
end;
function lcm(a,b:int64):int64;
var flag:int64;
begin
flag:= a*b div gcd(a,b);
lcm:=flag;
end;
begin
assign(f,'officer.in');
reset(f);
assign(g,'officer.out');
rewrite(g);
readln(f,n);
fillchar(st,sizeof(st),true);
for k:=1 to n do
begin readln(f,a);
ss[k]:=a;
end;
max:=1;
for k:=1 to n do
begin
p:=0;
if st[k]=true then
begin
ma:=swapp(ss[k]);
max:=lcm(ma,max);
end;
end;
writeln(g,max);
close(f);close(g);
end.