shuffle :: [Int] -> Int -> [Int] shuffle cards p = (head post) : pre ++ (tail post) where pre = take (p-1) cards; post = drop (p-1) cards main = do [n, _] <- getLine >>= return . map read . words getLine >>= print . head . foldl shuffle [1..n] . map read . words