#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int n;
int a[N];
bool vis[N];
int lp[N];
int dis[N];
int inloop(int v) {
  vis[v] = 1;
  int u = a[v];
  int cnt = 1;
  while (u != v && !vis[u]) {
    vis[u] = 1;
    ++cnt;
    u = a[u];
  }
  if (u == v) return cnt;
  return 0;
}
int dfsandsetlp(int v) {
  if (lp[v] > 0) return dis[v];
  int t = dfsandsetlp(a[v]);
  lp[v] = lp[a[v]];
  return dis[v] = t + 1;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return a / gcd(a, b) * b;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; ++i) {
    memset(vis, 0, sizeof(vis));
    int t = inloop(i);
    lp[i] = t;
  }
  for (int i = 1; i <= n; ++i) {
    if (!lp[i]) {
      dis[i] = dfsandsetlp(i);
    }
  }
  long long res = 1;
  for (int i = 1; i <= n; ++i) {
    res = lcm(res, lp[i]);
  }
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    mx = max(mx, dis[i]);
  }
  if (res < mx) {
    int t = mx / res;
    if (res * t == mx) {
      res = mx;
    } else {
      res = res * (t + 1);
    }
  }
  printf("%I64d\n", res);
  return 0;
}
