#include <bits/stdc++.h>
long long res;
int max;
const int N = 205;
int f[N], tt[N], cnt, next[N];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void dfs(int u) {
  cnt++;
  f[u] = -2;
  tt[u] = cnt;
  if (next[u] != u) {
    if (f[next[u]] == -2) {
      int tmp = tt[u] - tt[next[u]] + 1;
      res = lcm(res, tmp);
      cnt = tt[next[u]] - 1;
    } else {
      if (f[next[u]] == -1) {
        f[u] = 1;
      } else {
        if (f[next[u]] > 0) {
          f[u] = f[next[u]] + 1;
        } else {
          dfs(next[u]);
          if (tt[next[u]] <= cnt) {
            f[u] = f[next[u]] + 1;
          } else {
            if (tt[u] <= cnt)
              f[u] = 1;
            else
              f[u] = -1;
          }
        }
      }
    }
  } else {
    f[u] = -1;
    cnt--;
  }
  if (f[u] > max) max = f[u];
  if (f[u] == -2) f[u] = -1;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &next[i]);
  for (int i = 1; i <= n; i++) f[i] = 0;
  max = 0;
  res = 1;
  for (int i = 1; i <= n; i++)
    if (f[i] == 0) {
      cnt = 0;
      dfs(i);
    }
  if (max > 0) {
    if (max % res == 0)
      res = max;
    else
      res *= max / res + 1;
  }
  printf("%I64d", res);
  return 0;
}
