#include <iostream>
using namespace std;


int main(){

  int train , n[10] , count = 0;

  for( int i = 0; i < 10; i++ ){
    n[i] = 0;
  }

 while( cin >> train ){
   

   if( train != 0 ){
     ++count;
     n[count] = train;
   }else if( train == 0 ){
     for( int j = 10; j >= 0; j-- ){
       if( n[j] != 0 ){
	 cout << n[j] << endl;
	 n[j] = 0;
	 break;
       }
     }
   }



  
  
 }
 
  
  


  return 0;
}