#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    stack<int> stc;
    
    int a;
    while(cin>>a){
        if(a==0){
            cout<<stc.top()<<endl;
            stc.pop();
        }else{
            stc.push(a);
        }
    }
    
    return 0;
}

