#include <bits/stdc++.h>
using namespace std;
void reloc() { freopen("cards.in", "r", stdin); }
const int maxn = 200;
int n, a[maxn + 1], c[maxn + 1], mini = 0;
long long ans;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
}
long long findc(int i) {
  int vis[maxn + 1];
  memset(vis, 0, sizeof(vis));
  for (int j = 1; j <= n; j++) {
    vis[a[i]] = j;
    if (vis[a[a[i]]]) {
      int ans = j - vis[a[a[i]]] + 1;
      int k = vis[a[a[i]]];
      mini = max(mini, k);
      return ans;
    }
    i = a[i];
  }
  return 0;
}
void work() {
  ans = 1;
  for (int i = 1; i <= n; i++) {
    ans = lcm(ans, findc(i));
  }
  if (ans >= mini)
    printf("%lld\n", ans);
  else {
    int k = mini;
    k = (k - 1) / ans + 1;
    printf("%lld\n", k * ans);
  }
}
int main() {
  read();
  work();
  return 0;
}
