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