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

int main()
{
  vector<int> train;
  int in;
  while(cin>>in){
    if(in){
      train.push_back(in);
    }
    else{
      cout << train.back() << endl;
      train.pop_back();
    }
  }
  return 0;
}