#include <iostream>
#include <stack>
using namespace std;

int main()
{
	stack<int> s;
	int order;
	while (cin >> order)
	{
		if (order == 0)
		{
			cout << s.top() << endl;
			s.pop();
		}
		else
		{
			s.push(order);
		}
	}

	return 0;
}