#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> buffers;
    int buffer;

    while(cin >> buffer) {
        if(buffer == 0){
            cout << buffers[buffers.size()-1] << endl;
            buffers.pop_back();
            continue;
        }

        buffers.emplace_back(buffer);
    }
}
