//#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int car[100];
  int n,i=0;
  while(cin>>n){
    if(n==0){
      cout<<car[i]<<endl; i--;
    }
    else {
      i++; car[i]=n;
    }
  }
  return 0;
}