#include <iostream>
#include <stack>

using namespace std;

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

	}

	return 0;
}