#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int a[N], d[N], us[N];
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
void Solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  memset(d, -1, sizeof(d));
  int m = 0;
  long long res = 1;
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) {
      stack<int> s;
      int j;
      for (j = i; !us[j]; j = a[j]) {
        us[j] = true;
        s.push(j);
      }
      int c = d[j] == -1 ? 1 : d[j] + 1;
      if (d[j] == -1) {
        int l = 1;
        while (s.top() != j) {
          d[s.top()] = 0;
          s.pop();
          l++;
        }
        d[j] = 0;
        s.pop();
        res = res * l / GCD(res, l);
      }
      while (!s.empty()) {
        d[s.top()] = c;
        s.pop();
        c++;
      }
      m = max(m, c - 1);
    }
  }
  res *= max(1LL, (m + res - 1) / res);
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solve();
}
