#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    stack<int> s;
    int n, ans[100], ct = 0;
    while (cin>>n){
        if (n == 0) {
            ans[ct] = s.top();
            //cout << s.top() << endl;
            s.pop();
            ct++;
        } else {
            s.push(n);
        }
    }
    REP(i, ct){
        cout << ans[i] << endl;
    }
}
