#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main() {
	int data[10];
	stack<int> line;
	vector<int> top;
	int i = 0;

	while (cin >> data[i]) {
		++i;
	}

	for (auto i : data) {
		if (i == 0) {
			top.push_back(line.top());
			line.pop();
		}
		else {
			line.push(i);
		}
	}

	for (auto t : top) {
		cout << t << endl;
	}

	return 0;
}
