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

int main()
{
    int num;
    stack<int> s;

    while( cin >> num )
    {
        if( num == 0 )
        {
            cout << s.top() << endl;
            s.pop();
        }
        else
            s.push(num);
    }
    return 0;
}
