#include <iostream>
using namespace std;


int main(){

  int train , num[20] , k = 0 , count[20];

 for( int i = 0; i < 20; i++ ){
   count[i] = 0;
    num[i] = 0;
 }

 while( cin >> train ){
   
   ++k;
   num[k] = train;
    if( train == 0 ){
      for( int j = 20; j >= 0; j-- ){
	if( num[j] != 0 ){
	count[k] = num[j];
	num[j] = 0;
	break;
	}
      }
    }
  }
 
  
  for( int k = 0; k < 20; k++ ){
    if( count[k] != 0 ) cout  << count[k] << endl; 

  }


  return 0;
}