#include <iostream>
#include <stack>

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

    while(std::cin >> number){
        if(number != 0)
            st.push(number);
        else{
            std::cout << st.top() << std::endl;
            st.pop();
        }
    }
    
    return 0;
}