#include <iostream>
#include <stack>

using namespace std;


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

}