#include <cstdio>
#include <vector>
using namespace std;

vector<int> car,ans;

int main()
{
	while(true) {
		int n;
		scanf("%d",&n);
		if(n != 0) { car.push_back(n); }
		else {
			ans.push_back(car.back());
			car.pop_back();
		}
		if(car.empty()) { break; }
	}
	int Size = ans.size();
	for(int i=0;i<Size;++i) printf("%d\n",ans[i]);
	return 0;
}