#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
const long double E = 1e-11;
long long nsd(long long a, long long b) {
  while (a != 0 && b != 0)
    if (a > b)
      a %= b;
    else
      b %= a;
  return a + b;
}
long long nsk(long long a, long long b) { return a / nsd(a, b) * b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int to[n + 1];
  for (int i = 1; i <= n; i++) cin >> to[i];
  long long ans = 1, b = 0;
  for (int j = 1; j <= n; j++) {
    int t[n + 1];
    memset(t, -1, sizeof(t));
    int first = j, l = 0;
    for (first = j, l = 0; t[first] == -1; first = to[first]) t[first] = l++;
    ans = nsk(ans, l - t[first]);
    b = max(b, (long long)t[first]);
  }
  long long a = 1;
  while (a * ans < b) a++;
  cout << a * ans;
}
