#include <iostream>
#include <stack>
using namespace std;

int main() {
	int n, count = 0, a[10], i;
	stack<int> s;
	while (cin >> n,n>=0,!cin.eof()) {
		if (n > 0) s.push(n);
		else if (n == 0) { a[count++] = s.top(); s.pop(); }
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}