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

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