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

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