import Control.Monad
import Control.Applicative

main = do
  contents <- (fmap (read :: String -> Int) . lines) <$> getContents
  solve contents []

solve :: [Int] -> [Int] -> IO ()
solve [] _ = return ()
solve (x:xs) [] = solve xs (x:[])
solve (x:xs) (y:ys) = if x == 0
  then do
    putStrLn $ show y
    solve xs ys
  else solve xs (x:y:ys)