#include <iostream>
#include <stack>

using namespace std;

int main() {
    int n;
    stack<int> s;
    while (true) {
        cin >> n;
        if (cin.eof()) {
            return 0;
        }
        if (n == 0) {
            cout << s.top() << endl;
            s.pop();
        }
        else {
            s.push(n);
        }
    }
}