#include <bits/stdc++.h>
using namespace std;
long long a[205], f[205], mn[205], ans[205], pre[205];
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; i++) f[i] = i;
  for (long long k = 1; k <= n; k++) {
    for (long long i = 1; i <= n; i++) f[i] = a[f[i]];
    for (long long i = 1; i <= n; i++) {
      if (f[i] == f[f[i]]) {
        if (!mn[i])
          mn[i] = k;
        else if (k - mn[i] < mn[i]) {
          pre[i] = mn[i];
          mn[i] = k - mn[i];
        }
      }
    }
  }
  long long k = mn[1], mxpre = 0;
  for (long long i = 2; i <= n; i++) k = k / gcd(k, mn[i]) * mn[i];
  for (long long i = 1; i <= n; i++) mxpre = max(mxpre, pre[i]);
  long long mul = 1;
  if (mxpre) {
    mul = mxpre / k;
    if (mxpre % k != 0) mul++;
  }
  printf("%lld\n", k * mul);
}
