#include<iostream>
#include<vector>
int main(){
	std::vector<int> car,ans;
	int a;
	//int h=0;
	bool f=false;
	//std::vector<int>::iterator it=car.begin();
	while(std::cin>>a){
		if(a!=0&&!f){
			car.push_back(a);
			f=true;
		}else if(a!=0){
			//h++;
			//++it;
			car.push_back(a);
		}else{
			//ans.push_back(car[h]);
			//ans.push_back(n);
			ans.push_back(car.back());
			//it--;
			car.pop_back();
			//h--;
		}
	}
	for(int i=0;i<ans.size();i++){
		std::cout<<ans[i]<<std::endl;
	}

	return 0;
}