#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> line;
	int code;
	while (1) {
		cin >> code;
		if (code != 0) {
			line.push_back(code);
		}
		else {
			cout << *(line.end() - 1) << endl;
			line.pop_back();
		}
	}
	return 0;
}