# Volume1 0013
# Switching Railroad Cards

stack  = Array.new
answer = Array.new
while line = $stdin.gets
	n = line.chomp.to_i
	if n == 0
		answer << stack.pop
	else
		stack.push( n )
	end
end
answer.each{ |a| puts a }
