#include<bits/stdc++.h>
using namespace std;

int main(){
    stack<int> stk;
    int a;
    while(scanf("%d",&a) != EOF){
        if(a == 0){
            cout << stk.top() << endl;
            stk.pop();
        }else{
            stk.push(a);
        }
    }

    return 0;
}
