program officer(input,output);
var
i,n,t:integer;
ans:int64;
a:array[1..10000]of integer;
boo:array[1..10000]of boolean;
function lcs(a,b:int64):int64;
var
t,m:int64;
begin
m:=a*b;
if a<b then
begin
t:=a;
a:=b;
b:=t;
end;
t:=a mod b;
while t<>0 do
begin
a:=b;
b:=t;
t:=a mod b;
end;
exit(m div b);
end;
function go(const wh:integer):integer;
begin
if not(boo[wh]) then
begin
boo[wh]:=true;
exit(go(a[wh])+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
readln(a[i]);
ans:=1;
for i:=1 to n do
if not(boo[i]) then
begin
t:=go(i);
ans:=lcs(t,ans);
end;
writeln(ans);
close(input);
close(output);
end.