import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)



n = int(eval(input()))

T = [[] for _ in range(n)]

for i in range(1, n):

  a = int(eval(input()))

  a -= 1

  T[a].append(i)



def dfs(v):

  if not T[v]:

    return 0

  L = [dfs(i)+1 for i in T[v]]

  L.sort()

  for i in range(len(T[v]) - 1):

    L[i+1] = max(L[i]+1, L[i+1])

  return L[-1]



ans = dfs(0)

print(ans)
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)



import heapq



n = int(eval(input()))

T = [[] for _ in range(n)]

for i in range(1, n):

  a = int(eval(input()))

  a -= 1

  T[a].append(i)



def dfs(v):

  if not T[v]:

    return 0

  L = []

  for i in T[v]:

    heapq.heappush(L, dfs(i)+1)

  temp = heapq.heappop(L)

  while L:

    temp = max(temp+1, heapq.heappop(L))

  return temp



ans = dfs(0)

print(ans)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(eval(input()))
T = [[] for _ in range(n)]
for i in range(1, n):
    a = int(eval(input()))
    a -= 1
    T[a].append(i)


def dfs(v):
    if not T[v]:
        return 0
    L = [dfs(i) + 1 for i in T[v]]
    L.sort()
    for i in range(len(T[v]) - 1):
        L[i + 1] = max(L[i] + 1, L[i + 1])
    return L[-1]


ans = dfs(0)
print(ans)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import heapq

n = int(eval(input()))
T = [[] for _ in range(n)]
for i in range(1, n):
    a = int(eval(input()))
    a -= 1
    T[a].append(i)


def dfs(v):
    if not T[v]:
        return 0
    L = []
    for i in T[v]:
        heapq.heappush(L, dfs(i) + 1)
    temp = heapq.heappop(L)
    while L:
        temp = max(temp + 1, heapq.heappop(L))
    return temp


ans = dfs(0)
print(ans)

+import heapq + -    L = [dfs(i) + 1 for i in T[v]] -    L.sort() -    for i in range(len(T[v]) - 1): -        L[i + 1] = max(L[i] + 1, L[i + 1]) -    return L[-1] +    L = [] +    for i in T[v]: +        heapq.heappush(L, dfs(i) + 1) +    temp = heapq.heappop(L) +    while L: +        temp = max(temp + 1, heapq.heappop(L)) +    return temp