#include <iostream>
using namespace std;

int main()
{
  int n, i = 0, j = 0;
  int car[10] = {1};
  int output[10];
  while(cin >> n){
    if(n == 0){
      output[j] = car[i - 1];
      car[i - 1] = 0;
      i--;
      j++;
    }else{
      car[i] = n;
      i++;
    }
  }
  for(int i = 0; i < j; i++){
    cout << output[i] << endl;
  }
}