#include <iostream>
#include <vector>

int main(int argc,char* argv[]){
  std::vector<int> vec(1000);
  
  while(!std::cin.eof()){
    int temp;
    std::cin >> temp;
    if(temp == 0){
      std::cout << vec.back() << std::endl;
      vec.pop_back();
      continue;
    }else{
      vec.push_back(temp);
      continue;
    }
  }

  return 0;
  
}