local n = io.read("*n")
local parent, child, childpush = {}, {}, {}
local depth = {}
for i = 1, n do
  child[i] = {}
  depth[i] = 0
  childpush[i] = 0
end
parent[1] = 0
for i = 2, n do
  local a = io.read("*n")
  parent[i] = a
  table.insert(child[a], i)
end
local tasks = {}
for i = 1, n do
  if #child[i] == 0 then
    table.insert(tasks, i)
  end
end
local function sortfunc(x, y)
  return depth[x] > depth[y]
end
local mma = math.max
while 0 < #tasks do
  local c = tasks[#tasks]
  table.remove(tasks)
  local p = parent[c]
  childpush[p] = childpush[p] + 1
  if childpush[p] == #child[p] then
    table.sort(child[p], sortfunc)
    local d = 0
    for i = 1, #child[p] do
      d = mma(d, i + depth[child[p][i]])
    end
    depth[p] = d
    if 1 < p then
      table.insert(tasks, p)
    end
  end
end
print(depth[1])
