#include <iostream>
#include <stack>

using namespace std;

int main() {
	int i;
	stack<int> s;
	while (cin >> i) {
		if (i==0) {
			int o = s.top(); s.pop();
			cout << o << endl;
		} else {
			s.push(i);
		}		
	}
	return 0;
}