if true then
  fh=STDIN
else
  fh=open("in0013.txt")
end

stack=[]
out = []
while fh.gets do
  i=$_.chomp.to_i
  if i==0 then
    abort("stack empty") if stack.length==0
    out.push(stack.pop)
  else
    stack.push(i)
  end
end

puts out
fh.close