#include <iostream>
#include <vector>
using namespace std;

int main() {

  vector<long long int> num;
  long long int input;

  while( cin >> input ) {

    if ( input != 0 ) {

      num.push_back(input);

    }else {

      cout << num[ num.size()-1 ] << endl;
      num.pop_back();

    }

  }

  return 0;

}