#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int arr[210], n;
bool onCycle[210];
bool vis[210];
bool cycleCheck(int cur, int pr) {
  if (cur == pr) return 1;
  if (vis[cur]) return 0;
  vis[cur] = 1;
  return cycleCheck(arr[cur], pr);
}
int get(int cur, int pr) {
  vis[cur] = 1;
  if (cur == pr) return 0;
  return 1 + get(arr[cur], pr);
}
int solve(int cur) {
  if (onCycle[cur]) return 0;
  return 1 + solve(arr[cur]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &arr[i + 1]);
  for (int i = 0; i < n; ++i)
    onCycle[i + 1] = cycleCheck(arr[i + 1], i + 1), memset(vis, 0, sizeof vis);
  long long mn = 1;
  long long m = 1;
  for (int i = 0; i < n; ++i)
    if (onCycle[i + 1] && !vis[i + 1]) m = lcm(m, 1 + get(arr[i + 1], i + 1));
  for (int i = 0; i < n; ++i)
    if (!onCycle[i + 1]) mn = max(mn, 1LL * solve(i + 1));
  cout << ((mn + m - 1) / m) * m;
}
