{教官 NOIP模拟2010-11-17
Author: yangbohua
Time: 2010-11-17}
program officer;
var
a:array[0..10000] of longint;
b:array[0..10000] of boolean;
n,i,x,temp:longint;
ans:int64;
function gcd(y,z:int64):int64;
begin
if z=0
then gcd:=y
else gcd:=gcd(z,y mod z);
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]);
fillchar(b,sizeof(b),false);
for i:=1 to n do
begin
if a[i]=i then continue;
x:=i;
temp:=1;
while a[x]<>i do
begin
if b[x]=false then
begin
b[x]:=true;
x:=a[x];
temp:=temp+1;
end
else break
end;
if a[x]=i then
begin
if i=1
then ans:=temp
else ans:=(ans div gcd(ans,temp))*temp;
end;
end;
writeln(ans);
close(input);
close(output);
end.