#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
int a[210], b[210], now[210], d[210];
bool v[210];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(v, 0, sizeof(v));
  long long ans = 1;
  for (int i = 1; i <= n; i++)
    if (!v[i]) {
      int k = i, cnt = 0;
      memset(now, 0, sizeof(now));
      while (!v[k]) {
        v[k] = 1;
        now[k] = ++cnt;
        b[cnt] = k;
        k = a[k];
      }
      if (!now[k])
        for (int j = cnt; j; j--) d[b[j]] = d[a[b[j]]] + 1;
      else {
        for (int j = now[k]; j <= cnt; j++) d[b[j]] = 0;
        for (int j = now[k] - 1; j; j--) d[b[j]] = d[a[b[j]]] + 1;
        ans = ans * (cnt - now[k] + 1) / gcd(ans, cnt - now[k] + 1);
      }
    }
  long long tmp = ans;
  for (int i = 1; i <= n; i++)
    while (ans < d[i]) ans += tmp;
  cout << ans << endl;
  return 0;
}
