#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
   stack<int> s;
  while(scanf("%d",&a)!=EOF){

    if(a!=0){
      s.push(a);
    }
    else{
      cout<<s.top()<<"\n";
      s.pop();
    }
  }
}

