import Data.List (find)

main :: IO ()
main = do
  n <- readLn
  bn <- map (read :: String -> Int) . words <$> getLine
  print $ ans n bn

ans :: Int -> [Int] -> Maybe [Int]
ans 1 [j] = if j == 1 then Just [1] else Nothing
ans n ns = (\x -> if x == Nothing then Nothing else (\(Just y) -> y) x) . find $ 
  [fmap (a:) (ans (n-1) xs) | k <- [1..n], let a = ns !! (k-1), let xs = (drop (k-1) . take k) ns]
