#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> line;
	int pro;
	while(1)
	{
		cin>>pro;
		if(pro!=0){
			line.push_back(pro);
		}else{
			cout<<*(line.end()-1)<<endl;
			line.erase(line.end()-1);
		}
		if(line.empty())break;
	}
	return 0;
}