program gls;
var n,p,k,a,max:longint;
ss:array[1..10000]of longint;
st:array[1..10000]of longint;
sw:array[1..10000]of longint;
f,g:text;
procedure swapp(w:longint);
begin
if w<>k then
begin inc(p);
swapp(ss[w]);
end;
end;
function gcd(a,b:longint):longint;
var
t:longint;
begin
while a mod b <> 0 do
begin
t:=a mod b;
a:=b;
b:=t;
end;
gcd:=b;
end;
function lcm(a,b:longint):longint;
begin
lcm:= a*b div gcd(a,b);
end;
begin
assign(f,'officer.in');
reset(f);
assign(g,'officer.out');
rewrite(g);
readln(f,n);
for k:=1 to n do
begin readln(f,a);
ss[k]:=a;
end;
for k:=1 to n do
begin
p:=0;
swapp(ss[k]);
st[k]:=p+1;
end;
max:=st[1];
for k:=1 to k do
max:=lcm(max,st[k]);
writeln(g,max);
close(f);close(g);
end.