#include <cstdlib>
#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> cars;
  do {
    int car;
    cin >> car;
    if (car == 0) {
      cout << cars.top() << endl;
      cars.pop();
    } else {
      cars.push(car);
    }
  } while (!cars.empty());

  return 0;
}