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

int n;
stack<int> trail;
int main()
{
	while (cin >> n)
	{
		if (n)
			trail.push(n);
		else
		{
			cout << trail.top() << endl;
			trail.pop();
		}
	}
	return 0;
}