#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<int> stack;
  int input;
  while (cin >> input) {
    if (input == 0) {
      cout << stack.back() << endl;
      stack.pop_back();
    } else {
      stack.push_back(input);
    }
  }
}
