#include <iostream>
using namespace std;
int main(void){
    int in,i = 0,syako[1000];
    while(cin >> in){
        if(in != 0){
            syako[i] = in;
            i++;
        }
        else{
            cout << syako[i - 1] << endl;
            i--;
        }
    }
}
