#include <bits/stdc++.h>
using namespace std;
int n;
int f[500];
bool v[500];
int dis[500];
long long int ans = 1, aa;
int low;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
void go(int a, int b, int c) {
  if (v[f[b]]) {
    if (a == f[b])
      ans = lcm(ans, c);
    else
      low = max(low, dis[f[b]]);
    return;
  }
  v[f[b]] = 1;
  dis[f[b]] = c;
  go(a, f[b], c + 1);
}
int main() {
  scanf("%d", &n);
  for (int a = 1; a <= n; a++) scanf("%d", &f[a]);
  for (int a = 1; a <= n; a++) {
    memset(v, 0, sizeof(v));
    v[a] = 1;
    go(a, a, 1);
  }
  aa = ans;
  while (aa < low) aa += ans;
  printf("%I64d\n", aa);
  return 0;
}
