#include <bits/stdc++.h>
using namespace std;
int f[201], n, max_len = 0;
int circ[201] = {};
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  return b ? gcd(b, a % b) : a;
}
unsigned long long int lcm(unsigned long long int a, unsigned long long int b) {
  return a / gcd(a, b) * b;
}
unsigned long long int fn() {
  for (int i = 1; i <= n; ++i) {
    bool vis[201] = {};
    int pos, len = 0;
    for (int j = i; !vis[j]; j = f[j]) {
      vis[j] = true;
      ++len;
      pos = j;
    }
    for (int j = pos; f[j] != pos; j = f[j]) {
      ++circ[i];
    }
    ++circ[i];
    len -= circ[i];
    if (len > max_len) max_len = len;
  }
  unsigned long long int res = 1, ans;
  for (int i = 1; i <= n; ++i) {
    res = lcm(res, circ[i]);
  }
  for (ans = res; ans < max_len; ans += res)
    ;
  return ans;
}
int main(int argc, char const *argv[]) {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> f[i];
  }
  cout << fn() << endl;
  return 0;
}
