#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main (int argc, char const* argv[])
{
	auto ary = vector<int>();
	while(!feof(stdin))
	{
		int n;
		scanf("%d ",&n);
		if(n == 0)
		{
			cout << ary[ary.size()-1] << endl;
			ary.pop_back();
		}
		else
		{
			ary.push_back(n);
		}
	}
	return 0;
}