#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
bool fix[maxn];
int fixcount = 0;
int val[maxn][2];
int trans[maxn];
int vis[maxn];
int MIN = 0;
long long gcd(long long a, long long b) { return a % b ? gcd(b, a % b) : b; }
int ss(int i) {
  int cc[maxn] = {0};
  cc[i] = 1;
  int now = i;
  for (;;) {
    vis[now] = 1;
    int t = trans[now];
    if (cc[t]) {
      MIN = max(MIN, cc[t] - 1);
      return cc[now] + 1 - cc[t];
    }
    cc[t] = cc[now] + 1;
    now = t;
  }
}
int main() {
  int N;
  cin >> N;
  int count = 0;
  for (int(i) = 1; (i) <= (N); i++) {
    cin >> trans[i];
  }
  long long ans = 1;
  for (int(i) = 1; (i) <= (N); i++) {
    if (!vis[i]) {
      int temp = ss(i);
      ans = temp * ans / gcd(ans, temp);
    }
  }
  if (ans < MIN) {
    long long times = MIN / ans;
    if (MIN % ans) times++;
    ans *= times;
  }
  cout << ans;
  return 0;
}
