#include <iostream>
#include <stack>

int main(){
	std::stack<int> st;

	//car's number
	int num = 0;

    //Until the end of input
	while(std::cin >> num){
        //if num = 0, output and delete
		if(num == 0){
			std::cout << st.pop() << std::endl;
        //if num != 0, input    
		} else {
			st.push(num);
		}
	}
}