#include <iostream>
using namespace std;
int main(){
    int car[10];
    int num;
    int i=0;
    while(1){
        cin>>num;
        if(num!=0){
            car[i]=num;
            i++;}
        else{
            i--;
            cout<<car[i]<<endl;
            car[i]=0;
        }
    }
    return 0;
}