#include<iostream>
#include<vector>

using namespace std;

int main(){

  vector<int> V;

  while(1){
    int in;
    cin >> in;
    if(in != 0) V.push_back(in);
    else{
      cout <<  V.back() << endl;
      V.pop_back();
    }
    
    if(V.empty())break;
  }
  return 0;
}