program officer(input,output);
var
n,o:longint;
a:array[1..10000]of longint;
f:array[1..10000]of boolean;
p:array[1..10000]of longint;
head,i,j,ans:longint;
flag:boolean;
procedure dg(x,y,z:longint);
begin
if y=x then
begin
inc(head);
p[head]:=z;
end
else
begin
f[y]:=true;
dg(x,a[y],z+1);
end;
end;
function pro(x,y:longint):longint;
var
g:longint;
begin
if y>x then
begin
g:=y;
y:=x;
x:=g;
end;
if x mod y=0 then o:=y
else
begin
pro(y,x mod y);
end;
end;
begin
assign(input,'officer.in');
reset(input);
readln(n);
for i:=1 to n do readln(a[i]);
close(input);
for i:=1 to n do
if f[i]=false then
begin
f[i]:=true;
dg(i,a[i],1);
end;
ans:=1;
for i:=1 to head do
begin
o:=0;
pro(ans,p[i]);
ans:=(ans*p[i]) div o;
end;
assign(output,'officer.out');
rewrite(output);
writeln(ans);
close(output);
end.