import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





n = int(eval(input()))

a = [None]*(n-1)

from collections import defaultdict

c = defaultdict(list)

for i in range(n-1):

    num = int(eval(input()))

    c[num].append(i+2)



def sub(winner):

    l = len(c[winner])

    vs = []

    for p in c[winner]:

        vs.append(sub(p))

    vs.sort()

    ans = max([l] + [(l-i+v) for i,v in enumerate(vs)])

    return ans

ans = sub(1)

print(ans)
import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")



n = int(eval(input()))

a = [None]*(n-1)

from collections import defaultdict

c = defaultdict(list)

for i in range(n-1):

    num = int(eval(input()))

    c[num].append(i+2)



### 行きがけ順DFS

def dfs(start):

    q = [start] # now, prev

    us = []

    seen = set([start])

    while q:

        u = q.pop()

        us.append(u)

        for v in c[u]:

            if v in seen:

                continue

            q.append(v)

            seen.add(v)

    return us



us = dfs(1)

val = {}

for winner in us[::-1]:

    l = len(c[winner])

    vs = []

    for p in c[winner]:

        vs.append(val[p])

    vs.sort()

    ans = max([l] + [(l-i+v) for i,v in enumerate(vs)])

    val[winner] = ans

ans = val[1]

print(ans)
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = int(eval(input()))
a = [None] * (n - 1)
from collections import defaultdict

c = defaultdict(list)
for i in range(n - 1):
    num = int(eval(input()))
    c[num].append(i + 2)


def sub(winner):
    l = len(c[winner])
    vs = []
    for p in c[winner]:
        vs.append(sub(p))
    vs.sort()
    ans = max([l] + [(l - i + v) for i, v in enumerate(vs)])
    return ans


ans = sub(1)
print(ans)

import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = int(eval(input()))
a = [None] * (n - 1)
from collections import defaultdict

c = defaultdict(list)
for i in range(n - 1):
    num = int(eval(input()))
    c[num].append(i + 2)
### 行きがけ順DFS
def dfs(start):
    q = [start]  # now, prev
    us = []
    seen = set([start])
    while q:
        u = q.pop()
        us.append(u)
        for v in c[u]:
            if v in seen:
                continue
            q.append(v)
            seen.add(v)
    return us


us = dfs(1)
val = {}
for winner in us[::-1]:
    l = len(c[winner])
    vs = []
    for p in c[winner]:
        vs.append(val[p])
    vs.sort()
    ans = max([l] + [(l - i + v) for i, v in enumerate(vs)])
    val[winner] = ans
ans = val[1]
print(ans)

+### 行きがけ順DFS +def dfs(start): +    q = [start]  # now, prev +    us = [] +    seen = set([start]) +    while q: +        u = q.pop() +        us.append(u) +        for v in c[u]: +            if v in seen: +                continue +            q.append(v) +            seen.add(v) +    return us -def sub(winner): +us = dfs(1) +val = {} +for winner in us[::-1]: -        vs.append(sub(p)) +        vs.append(val[p]) -    return ans - - -ans = sub(1) +    val[winner] = ans +ans = val[1]