#include <iostream>
#include <queue>
#include <stack>
using namespace std;

int main()
{
        queue<int> op;
        queue<int> carrec;
        stack<int> car;
        int ops;
        int reccar;

        while(cin >> ops){
                op.push(ops);
        }

        while(!op.empty()){
                ops = op.front(); op.pop();
                if(ops != 0){
                        car.push(ops);
                }else if(ops == 0){
                        reccar = car.top();
                        carrec.push(reccar);
                        car.pop();
                }
        }

        while(!carrec.empty()){
                cout << carrec.front() << endl;
                carrec.pop();
        }

        return 0;
}