#include <iostream>
#include <stack>


int main()
{
	std::stack<int> train;
	int number;
	while(std::cin >> number){
		if(number == 0){
			std::cout << train.top() << std::endl;
			train.pop();
		}
		else
			train.push(number);
	}
	
	return 0;
}