#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int n, f[MAXN], vis[MAXN];
bool cyc[MAXN];
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> f[i];
  long long ans = 1;
  int ma = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      stack<int> stk;
      int cur = i;
      while (!vis[cur]) {
        vis[cur] = 1;
        stk.push(cur);
        cur = f[cur];
      }
      if (vis[cur] == 2) {
        while (!stk.empty()) vis[stk.top()] = 2, stk.pop();
        continue;
      }
      int cnt = 0;
      for (bool b = 1; b;) {
        int x = stk.top();
        stk.pop();
        vis[x] = 2;
        if (x == cur) b = 0;
        cnt++;
        cyc[x] = 1;
      }
      while (!stk.empty()) vis[stk.top()] = 2, stk.pop();
      ans = lcm(ans, cnt);
    }
  for (int i = 1; i <= n; i++) {
    int cur = i, cnt = 0;
    while (!cyc[cur]) cur = f[cur], cnt++;
    ma = max(ma, cnt);
  }
  long long ori = ans;
  while (ans < ma) ans += ori;
  cout << ans;
}
