#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main()
{
  stack<int> num;
  int x;
	vector<int> ans;

  while (cin >> x) {
    if (x != 0) {
      num.push(x);
    } else {
      ans.push_back(num.top());
      num.pop();
    }
  }

  x = ans.size();
  for (int i = 0; i < x; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}