from sys import stdin,stdout,setrecursionlimit
setrecursionlimit(300002)
from math import *
from collections import *
from pprint import pprint
import random
def read_list_line(elem_func=int):
return [elem_func(x) for x in stdin.readline().strip().split()]
def read_line(elem_func=str):
return elem_func(stdin.readline().strip())
def print_list_line(the_list,elem_func=str,sep=' ',end="\n"):
st=(sep.join([elem_func(x) for x in the_list]))+end
stdout.write(st)
return st
def print_line(st):
stdout.write(str(st)+"\n")
return st
ntest = 1 #
# ntest = read_line(int)
def main():
n = 200000
# n = read_line(int)
r=[0] + list(range(2,n+1))+[1]
# r=[0] + read_list_line(int)
stp=[[]]
for r0 in r:
stp[0].append(r0)
for i in range(1,int(log2(n*4))):
stp.append(stp[i-1].copy())
for j in range(1,n+1):
stp[i][j]=stp[i-1][stp[i-1][j]]
stable=[0]*(n+1)
for i in range(1,1+n):
stable[stp[len(stp)-1][i]]=1
def dfs(u):
if (stable[u]>=1):
return
v = r[u]
dfs(v)
stable[u]=stable[v]+1
for i in range(1,n+1):
if (stable[i]==0):
dfs(i)
print_line(max(stable)+1)
return 0
for test_case in range(1,1+ntest):
main()
ZnJvbSBzeXMgaW1wb3J0IHN0ZGluLHN0ZG91dCxzZXRyZWN1cnNpb25saW1pdApzZXRyZWN1cnNpb25saW1pdCgzMDAwMDIpCmZyb20gbWF0aCBpbXBvcnQgKgpmcm9tIGNvbGxlY3Rpb25zIGltcG9ydCAqCmZyb20gcHByaW50IGltcG9ydCBwcHJpbnQKaW1wb3J0IHJhbmRvbQpkZWYgcmVhZF9saXN0X2xpbmUoZWxlbV9mdW5jPWludCk6CiAgICByZXR1cm4gW2VsZW1fZnVuYyh4KSBmb3IgeCBpbiBzdGRpbi5yZWFkbGluZSgpLnN0cmlwKCkuc3BsaXQoKV0KIApkZWYgcmVhZF9saW5lKGVsZW1fZnVuYz1zdHIpOgogICAgcmV0dXJuIGVsZW1fZnVuYyhzdGRpbi5yZWFkbGluZSgpLnN0cmlwKCkpCiAKZGVmIHByaW50X2xpc3RfbGluZSh0aG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gICAgIGRmcyhpKQogICAgcHJpbnRfbGluZShtYXgoc3RhYmxlKSsxKQogICAgcmV0dXJuIDAKIApmb3IgdGVzdF9jYXNlIGluIHJhbmdlKDEsMStudGVzdCk6CiAgICBtYWluKCk=