#include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int> c;
  int n;
  while(cin >>n){
    if(n == 0){
      cout <<c.top()<<endl;
      c.pop();
    } else{
      c.push(n);
    }
  }
  return 0;
}