// -*- coding: utf-8 -*-
// Last-Updated : <2014/06/19 18:20:36 by samui>

#include <iostream>
#include <cstdio>
#include <string>

#include <vector>

int main(int argc, char **argv){
  int a;
  std::vector<int> b;
  while(std::cin >>a){
    if(a == 0){
      std::cout<<b[b.size()-1]<<std::endl;
      b.pop_back();
    }else{
      b.push_back(a);
    }

  }
  return 0;
}