#include<stdio.h>

int main(){
  int i = 0, x, count = 0;
  int data[100];
  while(count < 0){
    scanf("%d\n", x);
    data[i] = x;
    if(x == 0){
      count--;
      i--;
      if(count >= 0){
        printf("%d\n", data[i-1]);
      }
    }else{
      count++;
      i++;
    }
  }
  return 0;
}