#include<cstdio>
#include<iostream>
#include<stack>

using namespace std;       
int main(){
  stack<int> s;
  int a;
  while(cin >> a){
    if(a != 0){
      s.push(a);
    }else if(s.size() == 0){
      break;    
    }else{
      cout << s.top()<< endl;
      s.pop();
    }
  }
  return 0;
}