import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



N = int(eval(input()))

A = [int(eval(input())) for _ in range(N-1)]



graph = [[] for _ in range(N+1)]

for i,x in enumerate(A,2):

    graph[x].append(i)



def dfs(x):

    arr = [dfs(y) for y in graph[x]]

    if not arr:

        return 0

    arr.sort()

    return max(i+x for i,x in enumerate(arr[::-1],1))



answer = dfs(1)

print(answer)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N,*P = list(map(int,read().split()))



graph = [[] for _ in range(N+1)]

for i,x in enumerate(P,2):

    graph[i].append(x)

    graph[x].append(i)



root = 1

parent = [0] * (N+1)

order = []

stack = [root]

while stack:

    x = stack.pop()

    order.append(x)

    for y in graph[x]:

        if y == parent[x]:

            continue

        parent[y] = x

        stack.append(y)



dp = [0] * (N+1)

for v in order[::-1]:

    p = parent[v]

    A = [dp[c] for c in graph[v] if c != p]

    if not A:

        continue

    A.sort(reverse = True)

    A = [x + i for i,x in enumerate(A,1)]

    dp[v] = max(A)



answer = dp[1]

print(answer)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for i, x in enumerate(A, 2):
    graph[x].append(i)


def dfs(x):
    arr = [dfs(y) for y in graph[x]]
    if not arr:
        return 0
    arr.sort()
    return max(i + x for i, x in enumerate(arr[::-1], 1))


answer = dfs(1)
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, *P = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for i, x in enumerate(P, 2):
    graph[i].append(x)
    graph[x].append(i)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
dp = [0] * (N + 1)
for v in order[::-1]:
    p = parent[v]
    A = [dp[c] for c in graph[v] if c != p]
    if not A:
        continue
    A.sort(reverse=True)
    A = [x + i for i, x in enumerate(A, 1)]
    dp[v] = max(A)
answer = dp[1]
print(answer)

-input = sys.stdin.readline -sys.setrecursionlimit(10**7) -N = int(eval(input())) -A = [int(eval(input())) for _ in range(N - 1)] +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +N, *P = list(map(int, read().split())) -for i, x in enumerate(A, 2): +for i, x in enumerate(P, 2): +    graph[i].append(x) - - -def dfs(x): -    arr = [dfs(y) for y in graph[x]] -    if not arr: -        return 0 -    arr.sort() -    return max(i + x for i, x in enumerate(arr[::-1], 1)) - - -answer = dfs(1) +root = 1 +parent = [0] * (N + 1) +order = [] +stack = [root] +while stack: +    x = stack.pop() +    order.append(x) +    for y in graph[x]: +        if y == parent[x]: +            continue +        parent[y] = x +        stack.append(y) +dp = [0] * (N + 1) +for v in order[::-1]: +    p = parent[v] +    A = [dp[c] for c in graph[v] if c != p] +    if not A: +        continue +    A.sort(reverse=True) +    A = [x + i for i, x in enumerate(A, 1)] +    dp[v] = max(A) +answer = dp[1]