#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
int N;
int ar[MAXN];
int ind[MAXN];
int len[MAXN], dist[MAXN];
long long gcd(long long a, long long b) {
  if (a > 0) return gcd(b % a, a);
  return b;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void go(int st) {
  memset(ind, -1, sizeof(ind));
  int cur = st, clen = 0;
  do {
    ind[cur] = clen;
    ++clen;
    cur = ar[cur];
  } while (ind[cur] == -1);
  dist[st] = ind[cur];
  len[st] = clen - ind[cur];
}
int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> ar[i];
    --ar[i];
  }
  for (int i = 0; i < N; ++i) {
    go(i);
  }
  long long res = 1;
  int mdist = -1;
  for (int i = 0; i < N; ++i) {
    res = lcm(res, len[i]);
    if (mdist < dist[i]) mdist = dist[i];
  }
  long long tmp = res;
  while (res < mdist) res += tmp;
  cout << res << endl;
  return 0;
}
