program jiaoguan;
var
n,i,t:longint;
a,b:array[1..10000]of int64;
bz:array[1..10000]of boolean;
now,d:int64;
procedure gcd(a,b:int64);
begin
if b=0 then
begin
d:=a;
exit
end
else
gcd(b,a mod b)
end;
procedure huan(v,step:longint);
begin
if bz[v]=false then
begin
d:=step;
exit
end
else
begin
bz[v]:=false;
huan(a[v],step+1)
end
end;
begin
assign (input,'officer.in');
reset (input);
assign (output,'officer.out');
rewrite (output);
readln (n);
for i:=1 to n do
begin
readln (a[i]);
bz[i]:=true
end;
for i:=1 to n do
begin
if bz[i] then
begin
huan(i,0);
inc(t);
b[t]:=d
end;
end;
now:=b[1];
for i:=2 to t do
begin
if now mod b[i]=0 then
continue
else
begin
gcd(now,b[i]);
now:=now*b[i] div d;
end
end;
writeln (now);
close (input);
close (output)
end.