let rec select acc trace = function
  | [] -> acc
  | x :: xs -> select ((trace, x, xs) :: acc) (x :: trace) xs
let select xs = select [] [] xs

let rec solve acc = function
  | [] -> acc
  | bs ->
      select bs
      |> List.rev
      |> List.mapi (fun i x -> i, x)
      |> List.rev
      |> List.find (fun (i, (hd, b, tl)) -> i + 1 = b)
      |> (fun (_, (hd, b, tl)) -> solve (b :: acc) (List.rev_append hd tl))
let solve = solve []

let () = Scanf.scanf "%d\n" @@ fun n ->
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  try List.iter (Printf.printf "%d\n") @@ solve @@ Array.to_list bs
  with Not_found -> print_endline "-1"

