#include <iostream>
using namespace std;
class Stack_10{
private:
	int num;
	int x[10];
public:
	Stack_10(){num=0;};
	void push(int i){
		if(num<10){			
			x[num]=i;
			num++;
		}
	};
	int pop(){
		if(num>0){
			num--;
			return x[num];
		}
		else return -1;
	
	};
};
	
int main(int argc, char *argv[]){
	int car;
	Stack_10 stack;
	while(cin>>car){
	if(car>0) stack.push(car);
	else cout<<stack.pop()<<endl;
}

	return 0;
}