import Data.List main = do [n,_] <- map read . words <$> getLine as <- map read . words <$> getLine print (shuffle n as) shuffle n = head . foldl top [1..n] where top deck i = let c = head (drop (i-1) deck) in c : (delete c deck)