#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MAXN = (int)200 + 7;
const int INF = (int)1e9 + 7;
int n;
int to[MAXN];
int used[222];
long long gcd(long long a, long long b) {
  while (a && b) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return max(a, b);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &to[i]);
  }
  int lower = 1;
  long long lcm = 1;
  for (int i = 1; i <= n; i++) {
    int pLen = 0, cLen = 0;
    int v = i;
    vector<int> all;
    for (int it = 0; it < n + 10; it++) {
      all.push_back(v);
      v = to[v];
    }
    memset(used, 0, sizeof used);
    for (int i = 0; i < all.size(); i++) {
      if (used[all[i]]) {
        pLen = used[all[i]] - 1;
        cLen = i - pLen;
        break;
      }
      used[all[i]] = i + 1;
    }
    lcm = lcm / gcd(lcm, cLen) * 1ll * cLen;
    lower = max(lower, pLen);
  }
  int k = lower / lcm;
  if (lower % lcm) ++k;
  cout << lcm * k;
  return 0;
}
