main = do
  solve []
solve :: [Int] -> IO ()
solve il = do
  s <- getLine
  if null s
    then return ()
    else do
      let n = read s :: Int
      if n == 0
        then do
          putStrLn $ show $ last il
          solve (init il)
        else do
          solve (il ++ [n])