#include<iostream>
using namespace std;
int main(){
  int number,count1,count2,enter[11],leave[11],sum;
  sum=0;
  count1=0;
  count2=0;
  while(1){
    
    if( cin >> number && number>=0 && number<=10){
    
    if(number!=0){
      sum++;
      enter[count1]=number;
      count1++;}
    else if(number==0){
      count1--;
      leave[count2]=enter[count1];
      count2++;}
    if(sum-1<count2)break;
    }}
  for(int i=0;i<count2;i++){
    cout << leave[i]<< endl;
  }
 
  return 0;
}
      
      
      