#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main(){
    vector<int> array;
    int i = -1;
    while(cin >> i){
        if(i == 0){
            cout << array[array.size()-1]<< endl;
            array.pop_back();
        }else 
            array.push_back(i);
    }
    return 0;
}