#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cmath>
using namespace std;
int n,a[10001],t[10001];
bool f[10001];
long long gcd(long long a,long long b)
{
if (a<b)
swap(a,b);
if (b!=0)
return gcd(b,a%b);
return a;
}
int main()
{
int i,j,k,now;
long long ans;
ifstream fin("officer.in");
ofstream fout("officer.out");
fin>>n;
for(i=1;i<=n;i++)
fin>>a[i];
for(i=1;i<=n;i++)
if (!f[i])
{
now=i;
k=0;
do
{
now=a[now];
f[now]=true;
k++;
}while(now!=i);
j++;
t[j]=k;
}
ans=t[1];
for(i=2;i<=j;i++)
ans=(ans/gcd(ans,t[i]))*t[i];
fout<<ans<<endl;
fin.close();
fout.close();
return 0;
}