#include<vector>
#include<iostream>

using namespace std;

int main(){
  vector<int> rail;
  int rNum;
  while(cin >> rNum){//EOF de break
    if(rNum == 0){     
      cout << *rail.rbegin(); 
      rail.pop_back();
    }
    else  if(rNum <= 10 && rNum >= 0) rail.push_back(rNum);
  }  
  cout << endl;
}