#include <cassert>
#include <stack>
#include <iostream>


int main()
{
    std::stack<int> Stack;
    while(true){
        int n;
        std::cin >> n;
        if(n == 0){
            assert(Stack.empty() == false);
            std::cout << Stack.top() << std::endl;
            Stack.pop();
        }else{
            Stack.push(n);
        }
        if(std::cin.eof()) break;
    }
    return 0;
}