#include <bits/stdc++.h>
using namespace std;
const int maxn = 222;
int a[maxn], n;
bool incircle[maxn];
bool vis[maxn];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
  }
  memset(incircle, 0, sizeof incircle);
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    memset(vis, 0, sizeof vis);
    int c = 0, u = i;
    while (!vis[u]) c++, vis[u] = 1, u = a[u];
    if (u == i) {
      incircle[i] = 1;
      ans = ans / gcd(ans, c) * c;
    }
  }
  int mul = 1;
  for (int i = 0; i < n; i++) {
    int c = 0, u = i;
    while (!incircle[u]) c++, u = a[u];
    while (ans * mul < c) mul++;
  }
  ans *= mul;
  cout << ans << endl;
}
