var
i,n:longint;
t,ans,c:int64;
g:array[0..20000]of boolean;
a:array[0..20000]of longint;
function gcd(x,y:int64):int64;
begin
if y=0 then gcd:=x
else gcd:=gcd(y,x mod y);
end;
function go(k:longint):longint;
begin
if not g[k] then
begin
g[k]:=true;
go:=go(a[k])+1;
end
else exit(0)
end;
begin
assign(input,'officer.in'); reset(input);
assign(output,'officer.out'); rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
ans:=1;
for i:=1 to n do
if not g[i] then
begin
t:=go(i);
c:=gcd(ans,t);
ans:=(ans*t) div c;
end;
writeln(ans);
close(input);
close(output);
end.