#include <iostream>

using namespace std;

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