#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  
  int a[10],c=0,num;

  while( scanf("%d",&num) != EOF ){

    if( num != 0 ){
      a[c]=num;
      c++;
    }else{
      cout <<a[c-1]<<endl;
      c--;
    }   

  }
  return 0;

}