#include <iostream>
#include <stack>
#include <vector>
int main(){
  std::stack<int> i;
  std::vector<int> o;
  int n;
  while(std::cin>>n){
    if(!n)o.push_back(i.top()),i.pop();
    else{i.push(n);}
    if(i.empty()&&!o.empty())break;
  }
  std::vector<int>::iterator it = o.begin();
  while(it!=o.end()){
    std::cout<<*it<<std::endl;
    it++;
  }
  return 0;
}