#include<iostream>
#include<stack>

using namespace std;

int main() {

	int n;
	stack<int> line;

	while (cin >> n) {
		if (n == 0) {
			cout << line.top() << endl;
			line.pop();
		}
		else {
			line.push(n);
		}
	}

	return 0;
}