let rec dfs ans left bs s n =
(*  print_string "left: "; List.iter (fun n -> Printf.printf "%d; " n) left;
  print_string ", ";
  print_string "bs: "; List.iter (fun n -> Printf.printf "%d;" n) bs;
  print_string ", ";
  print_string "s: "; print_int s;
  print_string ", ";
  print_string "n: "; print_int n;
  print_endline "";*)
  if bs = [] && left = [] then Some ans
  else if s > n then ((*print_endline "None";*) None)
  else
    begin
      match bs with
      | [] -> Some ans
      | b::bs -> if b = s then 
                   begin
                     match dfs (b::ans) [] (left@bs) 1 (n - 1) with
                     | None -> dfs ans (left@[b]) bs (s + 1) n
                     | Some ans -> Some ans
                   end
                 else dfs ans (left@[b]) bs (s + 1) n
    end

let _ =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let bs = Array.make n 0 in
  for i = 0 to n - 1 do
    Scanf.scanf (if i <> n - 1 then "%d " else "%d\n") (fun b -> bs.(i) <- b)
  done;
  dfs [] [] (Array.to_list bs) 1 n 
  |> (function | None -> print_int (-1) 
               | Some ans -> List.iter (fun n -> print_endline @@ string_of_int n) ans)