import sys

sys.setrecursionlimit(10**5)

from collections import defaultdict



n = int(eval(input()))

e = [[] for i in range(n)]

for i in range(1,n):

    x = int(eval(input()))

    e[x-1].append(i)



def dfs(x):



    count = len(e[x])

    if count == 0:

        return 0

    d = defaultdict(int)

    ma = 0

    s = set()

    for nex in e[x]:

        v = dfs(nex)

        d[v] += 1

        s.add(v)

        ma = max(ma,v)

    now = count

    bef = 0

    for v in sorted(list(s),reverse=True):

        bef += d[v]

        now = max(now,bef+v)

    return now



print((dfs(0)))
import sys

sys.setrecursionlimit(10**5)



n = int(eval(input()))

e = [[] for i in range(n)]

for i in range(1,n):

    x = int(eval(input()))

    e[x-1].append(i)



def dfs(x):

    count = len(e[x])

    if count == 0:

        return 0

    l = []

    for nex in e[x]:

        l.append(dfs(nex))

    l.sort(reverse=True)

    now = count

    for i in range(count):

        now = max(now,l[i]+i+1)

    return now

print((dfs(0)))
import sys

sys.setrecursionlimit(10**5)
from collections import defaultdict

n = int(eval(input()))
e = [[] for i in range(n)]
for i in range(1, n):
    x = int(eval(input()))
    e[x - 1].append(i)


def dfs(x):
    count = len(e[x])
    if count == 0:
        return 0
    d = defaultdict(int)
    ma = 0
    s = set()
    for nex in e[x]:
        v = dfs(nex)
        d[v] += 1
        s.add(v)
        ma = max(ma, v)
    now = count
    bef = 0
    for v in sorted(list(s), reverse=True):
        bef += d[v]
        now = max(now, bef + v)
    return now


print((dfs(0)))

import sys

sys.setrecursionlimit(10**5)
n = int(eval(input()))
e = [[] for i in range(n)]
for i in range(1, n):
    x = int(eval(input()))
    e[x - 1].append(i)


def dfs(x):
    count = len(e[x])
    if count == 0:
        return 0
    l = []
    for nex in e[x]:
        l.append(dfs(nex))
    l.sort(reverse=True)
    now = count
    for i in range(count):
        now = max(now, l[i] + i + 1)
    return now


print((dfs(0)))

-from collections import defaultdict - -    d = defaultdict(int) -    ma = 0 -    s = set() +    l = [] -        v = dfs(nex) -        d[v] += 1 -        s.add(v) -        ma = max(ma, v) +        l.append(dfs(nex)) +    l.sort(reverse=True) -    bef = 0 -    for v in sorted(list(s), reverse=True): -        bef += d[v] -        now = max(now, bef + v) +    for i in range(count): +        now = max(now, l[i] + i + 1)