#include <bits/stdc++.h>
using namespace std;

int main() {
	vector<int> v(10);
	int n, j = 0;
	while (cin >> n) {
		if (n) {
			v.at(j) = n;
			j++;
		}
		else {
			j--;
			cout << v.at(j) << endl;
			v.at(j) = 0;
		}
	}
}
