import Data.List
import Data.Maybe
main = do
  _ <- getLine
  bs <- map read . words <$> getLine
  putStrLn $ if all (>=0) (g bs) then unlines (map show (g bs)) else "-1"

f xs x
  | fromMaybe (-1) (elemIndex x xs) == -1 = 0
  | fromMaybe 0 (elemIndex x xs) + 1 < x = 1
  | otherwise = 0

g [] = []
g [n] = [n]
g ys = if all (==0) (map (f ys) [1..(maximum ys)]) then [ys !! lidx] ++ g (drop (lidx+1) ys) ++  g (take lidx ys) else [-1]
  where lidx = length ys - fromMaybe 0 (elemIndex (minimum ys) (reverse ys)) - 1