#encoding:utf-8 No.0013 2014.10.1
shed = []
while gets
  car = $_.chomp
  if car == ""
    break
  end
  shed.push car.to_i
end

cars_out = []

until shed.length == 0
  shed.length.times do |i|
    if shed[i] == 0
      cars_out.push shed[i-1]
      shed.delete_at(i)
      shed.delete_at(i-1)
      break
    end
  end
end

puts cars_out