let rec make_tournament losers winner =
  List.map (make_tournament losers) (losers winner)
    |> List.sort compare
    |> List.fold_left (fun d d' -> 1 + max d d') 0

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init (n - 1) (fun _ -> Scanf.scanf "%d\n" (fun a -> a)) in
  let losers = Array.make n [] in
  Array.iteri (fun i a ->
    losers.(a - 1) <- i + 1 :: losers.(a - 1)) as_;
  Printf.printf "%d\n" (make_tournament (fun i -> losers.(i)) 0)
