#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int T[205];
int visit[205];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &T[i]);
    }
    long long ans1 = 1;
    long long ans2 = 1;
    for (int i = 1; i <= n; i++) {
      int t = i;
      int _size = 1;
      int doublevisit = -1;
      memset(visit, 0, sizeof(visit));
      visit[t] = 1;
      while (1) {
        t = T[t];
        if (visit[t]) {
          doublevisit = t;
          break;
        }
        _size++;
        visit[t] = _size;
      }
      if (t == i) {
        ans1 = lcm(ans1, _size - visit[doublevisit] + 1);
      }
      ans2 = max(ans2, visit[doublevisit] - 1LL);
    }
    long long ans = ans1;
    while (ans < ans2) {
      ans += ans1;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
