module Main where

import Data.Functor

main :: IO ()
main =  do
  { is <- getLine
  ; if is == "-" then done
    else do
      { [m] <- getInts
      ; ss  <- loop m
      ; putStrLn $ foldl shuffle is ss
      } >> main
}

shuffle :: [a] -> Int -> [a]
shuffle xs h = case splitAt h xs of
  (ys,zs) -> zs ++ ys

done :: IO ()
done = return ()

loop :: Int -> IO [Int]
loop 0 = return []
loop m = do
  { [h] <- getInts
  ; hs  <- loop (m-1)
  ; return (h:hs)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine