{教官 NOIP模拟2010-11-17
Author: yangbohua
Time: 2010-11-17}
program officer;
var
a:array[0..10001] of longint;
f:array[0..10001] of int64;
n,i,x: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(f,sizeof(f),0);
for i:=1 to n do
begin
x:=i;
repeat
x:=a[x];
f[i]:=f[i]+1;
until x=i;
end;
ans:=f[1];
for i:=2 to n do
begin
ans:=(ans div gcd(ans,f[i]))*f[i];
end;
writeln(ans);
close(input);
close(output);
end.