#include <bits/stdc++.h>
using namespace std;
long long mdc(long long a, long long b) {
  while (a && b)
    if (a > b)
      a %= b;
    else
      b %= a;
  return a + b;
}
long long mmc(long long a, long long b) { return (a * b) / mdc(a, b); }
long long n, f[210];
long long pot[210];
long long t[210], tot, ord[210];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    f[i]--;
    pot[i] = f[i];
  }
  long long tot = 1;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) ord[i] = -1;
    int now = k, curr = 0;
    while (ord[now] == -1) {
      ord[now] = curr++;
      now = f[now];
    }
    t[k] = curr - ord[now];
    tot = mmc(tot, t[k]);
  }
  long long ret = -1;
  for (int k = 1; ret == -1 && k <= 2 * n; k++) {
    int ok = 1;
    for (int i = 0; i < n; i++)
      if (pot[i] != pot[pot[i]]) ok = 0;
    if (ok) {
      ret = k;
      break;
    }
    for (int i = 0; i < n; i++) {
      pot[i] = f[pot[i]];
    }
  }
  if (ret == -1) ret = tot;
  cout << ret << endl;
  return 0;
}
