#include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

void push(int v) {
  train[sp] = v;
  sp++;
}

int main(){
  int out[10];
  int num, i = 0;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      out[i] = top();
      i++;
      pop();
    }else if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  for(i = 0; i < 10; i++){
    printf("%d\n", out[i]);
  }
  return 0;
}