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

f [] = []
f [n] = [n]
f xs = [xs !! lidx] ++ f (drop (lidx+1) xs) ++  f (take lidx xs)
  where lidx = length xs - fromMaybe 0 (elemIndex (minimum xs) (reverse xs)) - 1

g ys zs
  | null ys = zs
  | length zs + 1 >= head ys = g (tail ys) (take (head ys - 1) zs ++ [head ys] ++ drop (head ys - 1) zs)
  | otherwise = zs