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

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

	return 0;
}