#include <iostream>
#include <stack>
using namespace std;
int main() {
  stack<int> track;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << track.top() << endl;
      track.pop();
      continue;
    }
    track.push(n);
  }
}