#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> v;
    int num;
    while(cin) {
        cin >> num;
        if(num != 0) v.push_back(num);
        else {
            cout << v[v.size()-1] << endl;
            v.pop_back();
        }
    }
    return 0;
}