#include <iostream>
#include <vector>
using namespace std;
int main(){
  vector<int> a;
  int n;
  while(cin >> n){
    if(n==0){
      cout<< a.back();
      a.pop_back();//delete
    }else
      a.push_back(n);
  }
  return 0;
}