    #include <iostream>
    #include <stack>
    #include <vector>
     
    int main() {
    int n;
    std::stack<int> stc;
    std::vector<int> ans;
     
    while (std::cin >> n) {
    if (n == 0) {
    ans.push_back(stc.top());
    stc.pop();
    } else {
    stc.push(n);
    }
    }
     
    for (auto n : ans) {
    std::cout << n << std::endl;
    }
    }