#include <vector>
#include <iostream>

int main(){

	int a;
	int i = -1, j = -1;
	std::vector<int> array1;
	std::vector<int> array2;


	while(std::cin >> a){
		if(a != 0){
			array1.push_back(a);
			i++;
		}else{
			array2.push_back(array1[i--]);
			array1.pop_back();
			j++;
		}
	}
	
	while(j != -1){
		std::cout << array2[j--] <<  std::endl;
	}
}