import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)



import heapq



def main():

  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)

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

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

    return temp



  ans = dfs(0)

  print(ans)

  

if __name__ == "__main__":

  main()
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)



import heapq



def main():

  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)

  

if __name__ == "__main__":

  main()
import sys

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


def main():
    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)
        for _ in range(len(T[v]) - 1):
            temp = max(temp + 1, heapq.heappop(L))
        return temp

    ans = dfs(0)
    print(ans)


if __name__ == "__main__":
    main()

import sys

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


def main():
    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)


if __name__ == "__main__":
    main()

-        for _ in range(len(T[v]) - 1): +        while L: