var
i,c,n:longint;
total:int64;
a,f:array[0..20000]of longint;
ans:array[0..20000]of int64;
function gcd(x,y:int64):int64;
begin
if y=0 then gcd:=x
else gcd:=gcd(y,x mod y);
end;
procedure go(k:longint);
begin
if (total>0)and(k=i) then exit;
total:=total+1;
go(a[k]);
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]);
for i:=1 to n do
begin
total:=0;
go(i);
f[i]:=total;
end;
ans[1]:=f[1];
for i:=2 to n do
begin
c:=gcd(ans[i-1],f[i]);
ans[i]:=(ans[i-1]*f[i]) div c;
end;
writeln(ans[n]);
close(input);
close(output);
end.