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())
p    = list(map(int, input().split()))
g    = {}
deg  = {}

def push_d(deg, u, val):
    if u not in deg:
        deg[u] = 0
    deg[u] += val
    
def push_g(g, u, v):
    if u not in g:
        g[u] = []
    g[u].append(v)
    
for u, v in enumerate(p):
    u+=1
    
    push_d(deg, v, 1)
    push_g(g, u, v)
        
deg0 = [x for x in range(1, n+1) if x not in deg]
used = [0 for x in range(n+1)]
ans  = []

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

def total(arr):
    cur=1 
    for x in arr:
        cur = cur // gcd(cur, x) * x
    return cur    

def process(g, deg, deg0, u):
    if u in g:
        for v in g[u]:
            push_d(deg, v, -1)
        
            if deg[v] == 0:
                deg0.append(v)
    
def bfs(u):
    S = [u]
    i = 0
    while i < len(S):
        u = S[i]
        if u in g:
            for v in g[u]:
                if used[v] == 0:
                    used[v] = 1
                    S.append(v)
        i+=1
    return len(S)  
        
while len(deg0) > 0:
    u = deg0.pop()
    used[u] = 1 
    process(g, deg, deg0, u)
    
cnt = []    
for u in range(1, n+1):
    if used[u] == 0:
        used[u] = 1
        cnt.append(bfs(u))

ans = total(cnt)        
if  ans< n:
    cur = list(range(1, n+1))
    for _ in range(1, n+1):
        cur = mul(cur, p)
        if cur == mul(cur, cur):
            print(_)
            break 
else:
    print(ans)