#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  int car[10],car2[10]={0};
  stack<int> rail;
  int i=0,j=0;
  while(cin >> car[i]){
    if(car[i] != 0){
      rail.push(car[i]);
	}
    else{
      car2[j]=rail.top();
      rail.pop();
      j++;
    }
    i++;
  }
  for(i=0;i<j;i++){
    cout << car2[i] << endl;
  }
}