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

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