#include <bits/stdc++.h>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
using namespace std;
int f[256];
int done[256];
pair<int, int> dfs(int pos, int depth = 1) {
  if (done[pos]) return make_pair(depth - done[pos], max(1, done[pos] - 1));
  done[pos] = depth;
  const pair<int, int> ret = dfs(f[pos], depth + 1);
  done[pos] = 0;
  return ret;
}
template <class T>
T gcd(T a, T b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  const int n = getInt();
  for (int i = 0; i < (int)(n); i++) f[i] = getInt() - 1;
  long long ans = 1;
  map<int, int> memo;
  for (int i = 0; i < (int)(n); i++) {
    const pair<int, int> d = dfs(i);
    memo[d.first] = max(memo[d.first], d.second);
  }
  pair<int, int> mx;
  for (__typeof((memo).begin()) it = (memo).begin(); it != (memo).end(); it++) {
    const pair<int, int> d = *it;
    const int m = d.first;
    ans = ans * m / gcd<long long>(ans, m);
    mx = max(mx, make_pair(d.second, d.first));
  }
  ans = (mx.first + ans - 1) / ans * ans;
  cout << ans << endl;
  return 0;
}
