#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <istream>
#include <iomanip>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(int argc, char **argv){
	std::vector<int> stack;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		int n = std::stoi(buf);

		if(n != 0){
			stack.push_back(n);
		}
		else{
			std::cout << stack.back() << std::endl;
			stack.pop_back();
		}
	}
	return 0;
}
