#include <iostream>
using namespace std;

int main(){

  int stack[10] = {};
  int p = 0;

  while(cin >> stack[p]){
    if(stack[p] == 0){
      cout << stack[p-1] << endl;
      p--;
    }
    else{
      p++;
    }
  }
 
  return 0;
}