#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a;
  stack<int> st;
  while (cin >> a) {
    if (a == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.emplace(a);
    }
  }

  return 0;
}
