#include<stdio.h>
#include<stack>
using namespace std;
int main(){
	stack<int>cars;
	int i;
	while(~scanf("%d",&i)){
		if(i==0){
			printf("%d\n",cars.top());
			cars.pop();}
		else cars.push(i);}
	return 0;}
