program officer;
var
a,ans:array [1..10000] of longint;
n,sp:longint;
f1,f2:text;
procedure init;
var i:longint;
begin
assign(f1,'officer.in'); reset(f1);
assign(f2,'officer.out'); rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i]);
close(f1);
sp:=n;
end;
function lcm(x,y:longint):longint;
var i,j,temp:longint;
begin
i:=x; j:=y;
while i mod j<>0 do begin
temp:=j;
j:=i mod j;
i:=temp;
end;
lcm:=(x*y) div j ;
end;
procedure play;
var i,f,s,temp:longint;
begin
for i:=1 to n do begin
f:=a[i];
s:=0;
while f<>i do begin
s:=s+1;
f:=a[f];
end;
ans[i]:=s+1;
end;
while sp>1 do begin
sp:=sp-1;
temp:=lcm(ans[sp],ans[sp+1]);
ans[sp]:=temp;
end;
end;
procedure print;
begin
writeln(f2,ans[1]);
close(f2);
end;
begin
init;
play;
print;
end.