#include <iostream>
#include <stack>

using namespace std;

int main(){
    stack<int> in;
    for(int n; cin >> n; )
        if(n != 0) in.push(n);
        else cout << in.top() << endl, in.pop();

    return 0;
}