#include<iostream>
#include<vector>
using namespace std;

int main()
{
    int n;
    vector<int> car;
    while (cin >> n) {
        if (n) {
            car.push_back(n);
        }
        else {
            cout << car.back() << endl;
            car.pop_back();
        }
    }
    return 0;
}