#include <iostream>
#include <stack>
using namespace std;

int main(){
  stack<int> cars;
  int n;
  while(cin >> n){
    if(n == 0){
      cout << cars.top() << endl;
      cars.pop();
    } else{
      cars.push(n);
    }
  }
  return 0;
}