#include<iostream>
#include <cstdlib>
#include<list>
#include<string>
#include<stack>
using namespace std;
int main(){
	int a;
	stack <int> b;
	while (cin >> a) {
		if (a != 0) {
			b.push(a);
		}
		else {
			cout << b.top() << endl;
			b.pop();
		}
	}
    return 0;
}