#include <bits/stdc++.h>
using namespace std;
int N;
int F[205];
long long len[205];
long long vis[205];
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> F[i];
  }
  long long max_to_cycle = 0;
  for (int x = 1; x <= N; ++x) {
    for (int j = 1; j <= N; ++j) vis[j] = 0;
    long long cnt = 0;
    int y = x;
    while (!vis[F[y]]) {
      vis[F[y]] = ++cnt;
      y = F[y];
    }
    max_to_cycle = max(max_to_cycle, vis[F[y]]);
    len[x] = cnt - vis[F[y]] + 1;
  }
  long long LCM = len[1];
  for (int i = 2; i <= N; ++i) {
    LCM = lcm(LCM, len[i]);
  }
  long long ret = LCM;
  while (ret < max_to_cycle) ret += LCM;
  cout << ret << endl;
}
