#include<iostream>
#include<vector>
int main(){
	std::vector<int> car,ans;
	int a;
	while(std::cin>>a){
		if(a!=0)car.push_back(a);
		else {
			std::vector<int>::iterator it=car.end();
			int *n=&*it;
			car.pop_back();
			ans.push_back(*n);
		}
	}
	for(int i=0;i<ans.size();i++){
		std::cout<<ans[i]<<std::endl;
	}
	return 0;
}