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

int main(){
	stack<int> stack;
	while(1){
		int n;
		cin >> n;
		if(n > 0){
			stack.push(n);
		}
		else {
			cout << stack.top() << endl;
			stack.pop();
		}
		if(stack.empty()){
			break;
		}
	}
	return 0;
}