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

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

  return 0;
}