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.
n = int(input())
f = list(map(int, input().split()))


def proov(res):
    for i in range(len(f)):
        if res[i] != res[res[i]]:
            return False
    return True

for i in range(len(f)):
    f[i] -= 1

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


used = [0] * n
depth = [0] * n
on_circle = [False] * n

def dfs(s, d):
    ans = (0, float("inf"))
    used[s] = 1
    depth[s] = d + 1
    if used[f[s]] == 1:
        used[s] = 2
        ans = (depth[s] - depth[f[s]] + 1, depth[f[s]])
    if not used[f[s]]:
        ans = dfs(f[s], d + 1)
    if (ans[1] <= depth[s]):
        on_circle[s] = True
    used[s] = 2
    return ans

res = list(range(n))
i = 0
circles = []
nok = 1

for i in range(n):
    if not used[i]:
        a = dfs(i, 0)
        if(a[0] != 0):
            circles.append(a[0])

for i in range(len(circles)):
    nok = (nok * circles[i]) // gcd(nok, circles[i])

i = 0
while(True):  
    res = [f[res[j]] for j in range(n)]
    #print(res)
    i += 1
    flag = True
    for j in range(n):
        flag = flag and on_circle[f[j]]
    if(flag):
        print(max(nok, (i + nok - 1) // nok * nok))
        break
    if proov(res):
        print(i)
        break
    
        
    



