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 PairingHeapNode = function PairingHeapNode(val) {
  _classCallCheck(this, PairingHeapNode);

  this.value = val;
  this.head = null;
  this.next = null;
};

function merge(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];
  }b.next = a.head;
  a.head = b;
  return a;
}

function mergeList(s, comp) {
  var n = new PairingHeapNode(null);
  while (s) {
    var a = s,
        b = null;
    s = s.next;a.next = null;
    if (s) {
      b = s;s = s.next;b.next = null;
    }
    a = merge(a, b, comp);a.next = n.next;
    n.next = a;
  }
  while (n.next) {
    var j = n.next;
    n.next = n.next.next;
    s = merge(j, s, comp);
  }
  return s;
}

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

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

  _createClass(PairingHeap, [{
    key: "push",
    value: function push(val) {
      this.root = merge(this.root, new PairingHeapNode(val), this.comp);
      return this;
    }
  }, {
    key: "top",
    value: function top() {
      return this.root ? this.root.value : null;
    }
  }, {
    key: "pop",
    value: function pop() {
      if (!this.root) return null;
      var ret = this.root.value;
      this.root = mergeList(this.root.head, this.comp);
      return ret;
    }
  }, {
    key: "empty",
    value: function empty() {
      return !!this.root;
    }
  }]);

  return PairingHeap;
})();


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

(function solve(lines){
  var pq = new PairingHeap();
  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);