import System.IO (isEOF)

main = main' []
    where
    main' xs = do
        quit <- isEOF
        if quit then return () else do
            x <- readLn
            xs' <- operate xs x
            main' xs'

operate :: [Int] -> Int -> IO [Int]
operate (x:xs) 0 = do
    print x
    return xs
operate xs x = return (x:xs)