import sys



limit = 10 ** 5 * 2

sys.setrecursionlimit(limit)



def calc_depth(n):

    if children[n] == set():

        return 0



    depth_l = [calc_depth(child) for child in children[n]]

    depth_l.sort(reverse=True)



    return max(depth + (i+1) for (i, depth) in enumerate(depth_l))



N = int(eval(input()))



children = [set() for i in range(N + 1)]



for i in range(N - 1):

    a = int(eval(input()))

    children[a].add(i + 2)



ans = calc_depth(1)



# print(children)



print(ans)
from sys import stdin, setrecursionlimit



setrecursionlimit(10**7)



def solve():

    N = int(stdin.readline())

    Adj = [[] for i in range(N)]



    for i in range(N - 1):

        a = int(stdin.readline()) - 1

        Adj[a].append(i + 1)



    ans = dfs(N, Adj, 0, -1)



    print(ans)



def dfs(N, Adj, v, p):

    dl = []



    for u in Adj[v]:

        if u == p:

            continue



        dl.append(dfs(N, Adj, u, v))



    dl.sort(reverse=True)



    if not dl:

        return 0



    res = max(dl[i] + i + 1 for i in range(len(dl)))



    return res



if __name__ == '__main__':

    solve()
import sys

limit = 10**5 * 2
sys.setrecursionlimit(limit)


def calc_depth(n):
    if children[n] == set():
        return 0
    depth_l = [calc_depth(child) for child in children[n]]
    depth_l.sort(reverse=True)
    return max(depth + (i + 1) for (i, depth) in enumerate(depth_l))


N = int(eval(input()))
children = [set() for i in range(N + 1)]
for i in range(N - 1):
    a = int(eval(input()))
    children[a].add(i + 2)
ans = calc_depth(1)
# print(children)
print(ans)

from sys import stdin, setrecursionlimit

setrecursionlimit(10**7)


def solve():
    N = int(stdin.readline())
    Adj = [[] for i in range(N)]
    for i in range(N - 1):
        a = int(stdin.readline()) - 1
        Adj[a].append(i + 1)
    ans = dfs(N, Adj, 0, -1)
    print(ans)


def dfs(N, Adj, v, p):
    dl = []
    for u in Adj[v]:
        if u == p:
            continue
        dl.append(dfs(N, Adj, u, v))
    dl.sort(reverse=True)
    if not dl:
        return 0
    res = max(dl[i] + i + 1 for i in range(len(dl)))
    return res


if __name__ == "__main__":
    solve()

-import sys +from sys import stdin, setrecursionlimit -limit = 10**5 * 2 -sys.setrecursionlimit(limit) +setrecursionlimit(10**7) -def calc_depth(n): -    if children[n] == set(): -        return 0 -    depth_l = [calc_depth(child) for child in children[n]] -    depth_l.sort(reverse=True) -    return max(depth + (i + 1) for (i, depth) in enumerate(depth_l)) +def solve(): +    N = int(stdin.readline()) +    Adj = [[] for i in range(N)] +    for i in range(N - 1): +        a = int(stdin.readline()) - 1 +        Adj[a].append(i + 1) +    ans = dfs(N, Adj, 0, -1) +    print(ans) -N = int(eval(input())) -children = [set() for i in range(N + 1)] -for i in range(N - 1): -    a = int(eval(input())) -    children[a].add(i + 2) -ans = calc_depth(1) -# print(children) -print(ans) +def dfs(N, Adj, v, p): +    dl = [] +    for u in Adj[v]: +        if u == p: +            continue +        dl.append(dfs(N, Adj, u, v)) +    dl.sort(reverse=True) +    if not dl: +        return 0 +    res = max(dl[i] + i + 1 for i in range(len(dl))) +    return res + + +if __name__ == "__main__": +    solve()