#include<iostream>
#include<stack>
using namespace std;

int main(){
  stack<int> s;
  int n;
  do{
    cin>>n;
    if(n == 0){
      cout<<s.top()<<endl;
      s.pop();
    }else{
      s.push(n);
    }
  }while(s.size() != 0);
  return 0;
}