var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var SkewHeapNode = function SkewHeapNode(val) {
  _classCallCheck(this, SkewHeapNode);

  this.left = null;
  this.right = null;
  this.value = val;
};

function meld(a, b, comp) {
  if (!(a && b)) return a || b;
  if (comp(a.value, b.value)) {
    ;
    var _ref = [b, a];
    a = _ref[0];
    b = _ref[1];
  }a.right = meld(a.right, b, comp);
  var _ref2 = [a.right, a.left];
  a.left = _ref2[0];
  a.right = _ref2[1];

  return a;
}

var SkewHeap = (function () {
  function SkewHeap(comp) {
    _classCallCheck(this, SkewHeap);

    this.comp = comp || function (a, b) {
      return a < b;
    };
    this.root = null;
  }

  _createClass(SkewHeap, [{
    key: "push",
    value: function push(val) {
      this.root = meld(this.root, new SkewHeapNode(val), this.comp);
      return this;
    }
  }, {
    key: "pop",
    value: function pop() {
      if (!this.root) return null;
      var ret = this.root;
      this.root = meld(this.root.right, this.root.left, this.comp);
      return ret.value;
    }
  }, {
    key: "merge",
    value: function merge(other) {
      this.root = meld(this.root, other.root, this.comp);
      return this;
    }
  }, {
    key: "empty",
    value: function empty() {
      return !!this.root;
    }
  }]);

  return SkewHeap;
})();

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

(function solve(lines){
  var pq = new SkewHeap();
  lines.forEach(function(line){
    words = line.split(" ");
    if(words[0] === "insert"){
      pq.push(parseInt(words[1]));
    }else if(words[0] === "extract"){
      console.log(pq.pop());
    }
  });
})(lines);