#include<iostream>
using namespace std;

int main()
{
	int train[100000]={};
	long int i=0;
	while(1){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
		if(i==0) break;
	}
}