#include <bits/stdc++.h>
using namespace std;
int N;
int s[205];
long long gcd(long long a, long long 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); }
bool vis[200];
vector<int> path;
pair<long long, long long> check(int l) {
  memset(vis, 0, sizeof(vis));
  path.clear();
  for (int i = 0; !vis[l]; i++) {
    vis[l] = true;
    path.push_back(l);
    l = s[l];
  }
  for (int j = 0; j < path.size(); j++)
    if (path[j] == l) return make_pair(j, path.size() - j);
  return make_pair(0, 0);
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    s[i]--;
  }
  long long mv = 0;
  long long lc = 1;
  for (int i = 0; i < N; i++) {
    pair<long long, long long> p = check(i);
    lc = lcm(lc, p.second);
    mv = max(mv, p.first);
  }
  if (mv > lc) {
    long long r = (mv + lc - 1) / lc;
    cout << r * lc << endl;
  } else
    cout << lc << endl;
}
