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