program officer(input,output);
var
n,o:longint;
a:array[1..10000]of int64;
f:array[1..10000]of boolean;
p:array[1..10000]of int64;
head,i,j:longint;
ans:int64;
flag:boolean;
procedure dg(x:longint;y:int64;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:int64):int64;
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.