#include <stack>
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	stack<int> s;

	vector<int> Ans;

	int temp;

	while (true)
	{
		cin >> temp;

		if (temp != 0)
		{
			s.push(temp);
		}
		else
		{
			Ans.push_back(s.top());

			s.pop();
		}

		if (s.empty())
		{
			break;
		}
	}

	for (vector<int>::size_type i = 0; i < Ans.size(); i++)
	{
		cout << Ans[i] << endl;
	}

	return 0;
}