let _ = Scanf.scanf "%d" @@ fun n ->
  let c = Array.init (n+1) (fun _ -> []) in
  for i = 2 to n do Scanf.scanf " %d" (fun x -> c.(x) <- i :: c.(x)) done;

  let rec dfs v =
    List.map dfs c.(v)
    |> List.sort (fun x y -> y-x)
    |> List.mapi (fun i e -> e+i+1)
    |> List.fold_left max 0
  in
  dfs 1 |> Printf.printf "%d\n"