0小朋友崇拜圈 - 蓝桥云课 (lanqiao.cn)
sys.setrecursionlimit(1000000)
# 请在此输入您的代码
n=int(input())
w=[0]+list(map(int,input().split()))
used=[[0,0] for i in range(n+1)]
def dfs(k):
global cnt
if used[k][0] and used[k][1]:
return
if used[k][0] and not used[k][1] :
cnt+=1
used[k][1]=1
dfs(w[k])
used[k][0]=1
dfs(w[k])
max_=0
for i in range(1,n+1):
if not used[i][0]:
cnt=0
dfs(i)
max_=max(max_,cnt)
print(max_)