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

int main()
{
	vector<int> train;
	for (int i = 0, n; i < 10 && cin >> n;) {
		switch (n) {
		case 0:
			cout << train.back() << endl;
			train.pop_back();
			i++;
			break;
		default:
			train.push_back(n);
		}
	}
	return 0;
}