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

int main()
{
	int n;
	vector<int> cars;
	vector<int> order;
	while (cin >> n) {
		if (n==0)  {
			order.push_back(cars.back());
			cars.pop_back();
		}
		else
			cars.push_back(n);
		if (cars.size() == 0)
			break;
	}

	for (int i=0;i<order.size();i++)
		cout << order[i] << endl;

	return 0;
}