#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 10010
using namespace std;
long long a[maxn],cnt[maxn],n,t;
bool vis[maxn];
long long gcd(long long a,long long b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int main(){
freopen("officer.in","r",stdin);
freopen("officer.out","w",stdout);
scanf("%lld",&n);
for(long long i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
for(long long i=1;i<=n;i++)
{
t=a[i];
while(i!=t)
{
t=a[t];
cnt[i]++;
}
cnt[i]++;
}
long long ans=1;
for(long long i=1;i<=n;i++)
{
ans=( cnt[i]/gcd(ans,cnt[i]) )*ans;
}
printf("%lld",ans);
}