#include <iostream>
#include <stack>

int main(void){
    int num;
    std::stack<int> st;
    while(std::cin >> num){
        if(num == 0){
            std::cout << st.top() << std::endl;
            st.pop();
        } else {
            st.push(num);
        }
    }
}