#include <iostream>
#include <stack>

using namespace std;

int main()
{
  int val;
  stack<int> stk;

  while(cin>>val){
    if(val == 0){
      cout << stk.top() << endl;
      stk.pop();
    }
    else stk.push(val);
  }

  return 0;
}