#include <iostream>

using namespace std;

int main(){
  short stack[10]={0};
  short *pstack=stack;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      cout<<*pstack<<endl;
    }
    if(pstack==stack) break;
  }
}