let rec dfs ans left bs s n =
  if bs = [] && left = [] then Some ans
  else if s > n then None
  else
    begin
      match bs with
      | [] -> Some ans
      | b::bs -> 
         if b < s then None
         else if b = s then 
           begin
             match dfs (b::ans)
                     [] (List.fold_left (fun acc l -> l::acc) bs left)
                     1 (n - 1) with
             | None -> dfs ans (b::left) bs (s + 1) n
             | Some ans -> Some ans
           end
         else dfs ans (b::left) 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)