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

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