#include <bits/stdc++.h>
using namespace std;
const int MAX = 220;
int a[MAX];
bool u[MAX];
bool bio[MAX];
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  long long ans = 1;
  for (int i = (0); i < (n); ++i) {
    int x = i, c = 0;
    for (int j = (0); j < (n); ++j) bio[j] = false;
    while (!bio[x]) {
      c++;
      bio[x] = true;
      x = a[x];
    }
    if (x == i) {
      u[x] = true;
      ans = ans / gcd(ans, c) * c;
    }
  }
  int maks = 0;
  for (int i = (0); i < (n); ++i) {
    int c = 0, x = i;
    while (!u[x]) c++, x = a[x];
    int j = 1;
    while (j * ans < c) j++;
    maks = max(maks, j);
  }
  ans *= maks;
  cout << ans << endl;
  return 0;
}
