# coding: utf-8
#

def switch_railroad
  railroad = []
  loop do
    num = gets.chomp.to_i
    if num == 0 then
      puts railroad.pop
    else
      railroad.push num
    end
  end
end

switch_railroad