local mmi, mma = math.min, math.max
local n = io.read("*n")
local edge = {}
local ccnt = {}
local nodetask = {}
local len = {}
for i = 1, n do
  ccnt[i] = 0
  edge[i] = {}
  nodetask[i] = {}
  len[i] = 0
end
for i = 2, n do
  local a = io.read("*n")
  table.insert(edge[i], a)
  ccnt[a] = ccnt[a] + 1
end
local tasks = {}
for i = 2, n do
  if ccnt[i] == 0 then
    table.insert(tasks, i)
  end
end
for i = 1, n do
  local src = tasks[i]
  if 0 < #nodetask[src] then
    table.sort(nodetask[src])
    local nts = nodetask[src]
    local v = nts[1] + 1
    for j = 2, #nts do
      v = 1 + mma(v, nts[j])
    end
    len[src] = v
  end
  local lensrc = len[src]
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    local ccntdst= ccnt[dst]
    if 1 <= ccntdst then
      table.insert(nodetask[dst], lensrc)
      ccnt[dst] = ccntdst - 1
      if ccntdst == 1 then
        table.insert(tasks, dst)
      end
    end
  end
end
print(len[1])
