program officer;
var
a,b:array[0..10000]of longint;
c:array[1..10000]of boolean;
i,j,k,l:longint;
n,m,p:longint;
e:boolean;
procedure search(const x,y:longint);
begin
if x=i then
begin
inc(b[0]);
b[b[0]]:=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]);
for i:=1 to n do
if c[i]=false then
search(a[i],1);
m:=0;
for i:=1 to b[0] do
if b[i]>m then m:=b[i];
for i:=1 to b[0]-1 do
for j:=i+1 to b[0] do
if b[i]=b[j] then
begin
dec(b[0]);
for k:=j to b[0] do
b[j]:=b[j+1];
end;
i:=1;
repeat
p:=m*i;
e:=false;
for j:=1 to b[0] do
if (p mod b[j])<>0 then
begin
e:=true;
break;
end;
if e=false then break;
inc(i);
until 1=2;
writeln(p);
close(input);
close(output);
end.