#include <bits/stdc++.h>
using namespace std;
long long Nod(long long a, long long b) {
  if (a > b) a ^= b ^= a ^= b;
  return !a ? b : Nod(b % a, a);
}
long long Nok(long long a, long long b) { return a / Nod(a, b) * b; }
int mas[220];
void Solve() {
  int i, j, k, n, m;
  scanf("%d", &(n));
  for (i = 1; i <= n; i++) scanf("%d", &(mas[i]));
  int b = 0;
  long long lcm = 1;
  for (i = 1; i <= n; i++) {
    vector<int> step(n + 1, -1);
    int a = i;
    int k = 0;
    while (true) {
      step[a] = k++;
      a = mas[a];
      if (step[a] != -1) break;
    }
    b = max(b, step[a]);
    lcm = Nok(lcm, k - step[a]);
  }
  long long ans = lcm;
  while (ans < b) ans += lcm;
  printf("%I64d", ans);
}
int main() {
  Solve();
  return 0;
}
