#include<iostream>
#include<cstdio>
#define UP unsigned long long
using namespace std;
UP tot=1;
int a[100001];
int n,i;
UP gcd(UP x,UP y)
{
UP p=x,q=y,r=x%y;
while (r)
{
p=q;
q=r;
r=p%q;
}
return q;
}
int main()
{
freopen("officer.in","r",stdin);
freopen("officer.out","w",stdout);
scanf("%d",&n);
for (i=1; i<=n; ++i) scanf("%d",&a[i]);
for (i=1; i<=n; ++i)
{
UP l=0;
int t=i;
do
{
t=a[t];
l++;
}while (t!=i);
tot=(l/gcd(tot,l))*tot;
}
cout<<tot<<endl;
return 0;
}