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