#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main(void)
{
  stack<int> in;
  queue<int> out;
  int n,c;
  cin>>c;
  in.push(c);
  while(!in.empty())
  {
    cin>>c;
    if(c==0){
      out.push(in.top());in.pop();
    }else{
      in.push(c);
    }
  }
  while(!out.empty())
  {
    cout<<out.front()<<endl;
    out.pop();
  }
  return 0;
}