Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., *n*} is such function <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/be90664fb67fc59aea0742746b0626ddab543582.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that for any <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/75df05ed78f11fc97381dcb0cd5b104b9483ca8f.png" style="max-width: 100.0%;max-height: 100.0%;"/> the formula *g*(*g*(*x*)) = *g*(*x*) holds.

Let's denote as *f*<sup class="upper-index">(*k*)</sup>(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*<sup class="upper-index">(1)</sup>(*x*) = *f*(*x*), *f*<sup class="upper-index">(*k*)</sup>(*x*) = *f*(*f*<sup class="upper-index">(*k* - 1)</sup>(*x*)) for each *k* &gt; 1.

You are given some function <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58da889a2e5c65797055ac8eba57b4a01abee69c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Your task is to find minimum positive integer *k* such that function *f*<sup class="upper-index">(*k*)</sup>(*x*) is idempotent.
In the first line of the input there is a single integer *n* (1 ≤ *n* ≤ 200) — the size of function *f* domain.

In the second line follow *f*(1), *f*(2), ..., *f*(*n*) (1 ≤ *f*(*i*) ≤ *n* for each 1 ≤ *i* ≤ *n*), the values of a function.
import sys

n = int(sys.stdin.readline())
a = list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

path_lens = []
cycle_lens = []
for i, v in enumerate(a):
	cur = i
	visited = []
	while cur not in visited:
		visited.append(cur)
		cur = a[cur]
	visited.append(cur)

	path_len = 0
	for j, x in enumerate(visited):
		if x in visited[j+1:]:
			break
		path_len += 1
	cycle_len = len(visited) - path_len - 1

	path_lens.append(path_len)
	cycle_lens.append(cycle_len)

# print(list(path_lens))
# print(list(cycle_lens))
def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

common_lcm = 1
for v in cycle_lens:
	common_lcm = common_lcm * v // gcd(common_lcm, v)
res = max(path_lens)
if common_lcm > 1:
	res += common_lcm
if res == 0:
	res = 1
print(res)