#include <bits/stdc++.h>
using namespace std;
int gcd(long long int a, int b) {
  if (b > a) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, int b) { return (a / gcd(a, b)) * b; }
long long int find_k(long long int a, int b) {
  if (b == 0) return a;
  int mod = b % a;
  if (mod == 0) return b;
  return a + b - mod;
}
int main() {
  int i, b = 0, j, k, n, f[200 + 1], cycle_length[200 + 1], cur_list[200 + 1],
         visited_cur[200 + 1], cycle_distance[200 + 1];
  bool visited[200 + 1];
  long long int a, ans;
  memset(cycle_distance, 0, sizeof(cycle_distance));
  memset(visited, 0, sizeof(visited));
  scanf("%i", &n);
  for (i = 1; i <= n; i++) scanf("%i", &f[i]);
  cycle_length[0] = 0;
  for (i = 1; i <= n; i++) {
    if (visited[i]) continue;
    k = i;
    memset(visited_cur, 0, sizeof(visited_cur));
    cur_list[0] = 0;
    while (!visited[k]) {
      cur_list[0]++;
      cur_list[cur_list[0]] = k;
      visited[k] = 1;
      visited_cur[k] = cur_list[0];
      k = f[k];
    }
    if (visited_cur[k]) {
      cycle_length[0]++;
      cycle_length[cycle_length[0]] = cur_list[0] + 1 - visited_cur[k];
      for (j = visited_cur[k] - 1; j > 0; j--)
        cycle_distance[cur_list[j]] = cycle_distance[cur_list[j + 1]] + 1;
    } else {
      cycle_distance[cur_list[cur_list[0]]] = cycle_distance[k] + 1;
      for (j = cur_list[0] - 1; j > 0; j--)
        cycle_distance[cur_list[j]] = cycle_distance[cur_list[j + 1]] + 1;
    }
    if (b < cycle_distance[i]) b = cycle_distance[i];
  }
  a = 1;
  for (i = 1; i <= cycle_length[0]; i++) a = lcm(a, cycle_length[i]);
  ans = find_k(a, b);
  printf("%I64d", ans);
  return 0;
}
