module Array = struct
  include Array
  let create ~len x = Array.make len x
end

module List = struct
  include List
  let fold_left l ~init ~f = List.fold_left f init l
end

let printf = Printf.printf

let () =
  Scanf.scanf "%d %d " (fun len k ->
      let towns = Array.create ~len [] in
      let capital_to = Scanf.scanf "%d " (fun i -> i-1) in
      for i = 1 to len-1 do
        Scanf.scanf "%d " (fun j ->
            towns.(j-1) <- (i :: towns.(j-1)))
      done;

      let rec count rest i =
        let l = towns.(i) in
        if rest = 0 then
          List.fold_left l ~init:0 ~f:(fun acc elt -> acc + 1 + count (k-1) elt)
        else
          List.fold_left l ~init:0 ~f:(fun acc elt -> acc + count (rest-1) elt)
      in

      let n = count k 0 in
      printf "%d\n" (n + if capital_to = 0 then 0 else 1))
