const int IN = 20, OUT = 100;
int data1[IN], data2[OUT];
int spA = 0, spB = 0;
int top(){
  return data1[spA - 1];
}
void pop(){
  spA--;
}

#include<stdio.h>
int main(){
  int i, n, c;
  while((c = getchar()) != EOF){
    scanf("%d", &n);
    if(n != 0){
      data1[spA] = n;
      spA++;
    }else{
      data2[spB] = top() ;
      spB++;
      pop();
    }
  }
  for(i = 0; i < spB; i++){
    printf("%d\n",data2[i]);
  }
  return 0;
}