program zzn;
type
arr=array[1..100]of integer;
var
ans,i,j,n:longint;
a:array[false..true]of arr;
b:array[1..10000]of integer;
map:array[1..10000]of longint;
procedure init;
begin
assign(input,'officer.in');
reset(input);
assign(output,'officer.out');
rewrite(output);
readln(n);
for i:=1 to n do readln(b[i]);
for i:=1 to n do a[not(odd(1)),i]:=i;
end;
procedure closef;
begin
close(input);
close(output);
end;
function ok(c:arr):boolean;
var
i:integer;
begin
for i:=1 to n do if c[i]<>i then exit(false);
exit(true);
end;
procedure main;
var
f1,f2:boolean;
begin
ans:=0;
for i:=1 to n do a[not(odd(1)),i]:=i;
while true do
begin
inc(ans);
f1:=not(odd(ans));
f2:=(odd(ans));
for i:=1 to n do a[f2,b[i]]:=a[f1,i];
if ok(a[f2]) then
begin
writeln(ans);
exit;
end;
end;
end;
function gcd(a,b:longint):longint;
begin
if a=0 then exit(b) else
exit(gcd(b mod a,a));
end;
function lcm(x,y:longint):qword;
begin
exit(x*y div (gcd(x,y)));
end;
procedure main2;
var
move:longint;
ans2:qword;
begin
for i:=1 to n do
begin
move:=1;
j:=b[i];
while j<>i do
begin
j:=b[j];
inc(move);
end;
map[i]:=move;
end;
ans2:=lcm(map[1],map[2]);
for i:=3 to n do
begin
ans2:=lcm(ans2,map[i]);
end;
writeln(ans2);
end;
begin
init;
if n<=100 then main else
main2;
end.