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.
def gcd(a,b):
	if b==0:
		return a
	return gcd(b,a%b)
def lcm(a,b):
	if a==0:
		return b
	if b==0:
		return a
	return a*b//gcd(a,b)
n=int(input())
f=list(map(int,input().split()))
for i in range(n):
	f[i]-=1
incyc=[0]*n
for v in range(n):
	u=v
	pok=0
	for _ in range(n):
		u=f[u]
		if u==v:
			pok=1
			break 
	if pok:
		incyc[v]=1
qs=[0]*n
for v in range(n):
	if incyc[v]:
		continue
	u=v
	now=0
	for _ in range(n):
		u=f[u]
		now+=1
		if incyc[u]:
			qs[v]=now
			break
l=0
ma=0
for v in range(n):
	if incyc[v]:
		u=v
		now=0
		for _ in range(n):
			u=f[u]
			now+=1
			if u==v:
				l=lcm(l,now)
				break
	else:
		# print(v,qs[v])
		ma=max(ma,qs[v])
x=(ma//l)*l
while x<ma or x==0:
	x+=l
print(x)