#include <iostream>
#include <stack>

using namespace std;

int main(void){
    stack<int> in;
    
    do{
        int num; cin >> num;
        if(num != 0) in.push(num);
        else{ cout << in.top() << endl; in.pop(); }
    }
    while(!in.empty());

    return 0;
}