import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  def loop(l:List[String],s:List[String]):Unit =
    if(l == Nil) return
    else {
      val i::lines = l
      if(i == "0") {
        val hd::tl = s
        b.append(hd+"\n")
        loop(lines,tl)
      } else {
        loop(lines,i::s)
      }
    }

  loop(stdin.getLines.toList,Nil)
  print(b.result)
}