#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main(){
    int a;
    vector<int> buffer;
    while(cin >> a){
        if(a == 0){
            cout << buffer.back() << endl;
            buffer.pop_back();
        }
        else{
            buffer.push_back(a);
        }
    }
}