var n,i,j,k:longint;
a,b,t:array[0..10000]of longint;
x:int64;
procedure go(t,s:int64);
var x,y:longint;
begin
x:=a[t];
if x<>i then go(x,s+1)
else begin b[i]:=s;exit;end;
end;
procedure swap(x,y:longint);
var d:longint;
begin
d:=x;x:=y;y:=d;
end;
function lcm(a1,a2:int64):int64;
begin
if a1<a2 then swap(a1,a2);
lcm:=a1;
while lcm mod a2>0 do inc(lcm,a1);
end;
begin
assign(input,'officer.in');reset(input);
assign(output,'officer.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(a[i]);
if a[i]=i then b[i]:=1;
end;
for i:=1 to n do
if a[i]<>i then go(i,1);
j:=0;
x:=b[1] ;
for i:=2 to n do
x:=lcm(x,b[i]);
writeln(x);
close(input);close(output);
end.