#include<cstdio>
#include<stack>
using namespace std;
int main(){
  stack<int> s;
  do{
    int num;scanf("%d",&num);
    if(num){
      s.push(num);
    }else{
      printf("%d\n",s.top());
      s.pop();
    }
  }while(!s.empty());
}