#include<iostream>
#include<stack>
#include<cstdio>
#include<vector>
using namespace std;
int a;


int main(int argc, char *argv[])
{
  stack<int> s;
  vector<int> m;
  while(cin>>a){
    if(a == 0){
      m.push_back(s.top());
      s.pop();
    }else{
    s.push(a);
	}
  }
  int S = m.size();
  for(int i= 0;i < S;i++){
    cout<<m[i]<< endl;
  }
  return 0;
}