#include <iostream>
#include <stack>

using namespace std;

void solve()
{
	stack<int> Stack;
	int Input;
	while(cin >> Input)
	{
		if(Input)
		{
			Stack.push(Input);
		}
		else
		{
			cout << Stack.top() << endl;
			Stack.pop();
		}
	}
}

int main()
{
	solve();
	return(0);
}