#include <bits/stdc++.h>
using namespace std;
int N;
int F[222];
int C[222];
long long gcd(long long a, long long b) { return (b) ? gcd(b, a % b) : a; }
int main() {
  scanf("%d", &N);
  int i, j;
  for (i = 1; i <= N; i++) scanf("%d", &F[i]);
  long long ans = 1;
  for (i = 1; i <= N; i++) {
    int u = i;
    for (j = 1; j <= N; j++)
      if ((u = F[u]) == i) break;
    if (j <= N) {
      C[i] = j;
      ans *= j / gcd(j, ans);
    } else
      C[i] = 0;
  }
  int dep = 0;
  for (i = 1; i <= N; i++) {
    if (C[i]) continue;
    int u = i;
    for (j = 1; j <= N; j++)
      if (C[u = F[u]]) break;
    dep = max(dep, j);
  }
  long long ret = ans;
  while (ret < dep) ret += ans;
  cout << ret << endl;
  return 0;
}
