#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstddef>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>

template <class TotallyOrderedSet> class pairing_heap {

public:
	using set_type = TotallyOrderedSet;
	using value_type = typename set_type::value_type;
	using const_reference = const value_type &;
	using size_type = std::size_t;

private:
	struct node_t {
		value_type value;
		std::unique_ptr<node_t> left, right;
		template <class... Args>
		node_t(Args &&... args) noexcept(
			std::is_nothrow_constructible<value_type, Args...>::value)
			: value(std::forward<Args>(args)...), left(), right() {}
	};
	using pointer = std::unique_ptr<node_t>;
	pointer root;
	size_type s;
	static pointer merge(pointer x, pointer y) noexcept(
		noexcept(set_type::less_equal(std::declval<value_type>(),
			std::declval<value_type>()))) {
		if (!set_type::less_equal(x->value, y->value))
			x.swap(y);
		y->right = std::move(x->left);
		x->left = std::move(y);
		return std::move(x);
	}
	static pointer mergelist(pointer curr) noexcept(
		noexcept(merge(std::declval<pointer>(), std::declval<pointer>()))) {
		pointer head, temp, next;
		while (curr) {
			next = std::move(curr->right);
			if (next) {
				temp = std::move(next->right);
				curr = merge(std::move(curr), std::move(next));
			}
			curr->right = std::move(head);
			head = std::move(curr);
			curr = std::move(temp);
		}
		if (head) {
			curr = std::move(head);
			head = std::move(curr->right);
		}
		while (head) {
			next = std::move(head->right);
			curr = merge(std::move(curr), std::move(head));
			head = std::move(next);
		}
		return std::move(curr);
	}

public:
	pairing_heap() noexcept : root(), s(0) {}

	bool empty() const noexcept { return !root; }
	size_type size() const noexcept { return s; }

	const_reference top() const noexcept {
		assert(!empty());
		return root->value;
	}

	void push(const value_type &x) {
		if (empty())
			root = std::make_unique<node_t>(x);
		else
			root = merge(std::move(root), std::make_unique<node_t>(x));
		++s;
	}
	void push(value_type &&x) {
		if (empty())
			root = std::make_unique<node_t>(std::move(x));
		else
			root = merge(std::move(root), std::make_unique<node_t>(std::move(x)));
		++s;
	}
	template <class... Args> void emplace(Args &&... args) {
		if (empty())
			root = std::make_unique<node_t>(std::forward<Args>(args)...);
		else
			root = merge(std::move(root),
				std::make_unique<node_t>(std::forward<Args>(args)...));
		++s;
	}

	void pop() noexcept(noexcept(mergelist(std::declval<pointer>()))) {
		assert(!empty());
		root = mergelist(std::move(root->left));
		--s;
	}

	pairing_heap &meld(pairing_heap &other) noexcept(
		noexcept(merge(std::declval<pointer>(), std::declval<pointer>()))) {
		if (!other.empty()) {
			s += other.s;
			other.s = 0;
			root = merge(std::move(root), std::move(other.root));
		}
		return *this;
	}
	pairing_heap &operator+=(pairing_heap &other) noexcept(
		noexcept(meld(std::declval<pairing_heap>()))) {
		return meld(other);
	}
};
#include <algorithm>
#include <limits>
#include <utility>

template <class T> class ordered_set {
public:
	using value_type = T;

	static bool less_equal(const value_type &x, const value_type &y) noexcept(noexcept(
		std::declval<value_type>()>=std::declval<value_type>())) {
		return x >= y;
	}
};

#include<cstdio>
#include<string>
void scan(std::string &s) {
	s.clear();
	int c = fgetc(stdin);
	while (c == ' ' || c == '\n') c = fgetc(stdin);
	while (c != ' '&&c != '\n') {
		s.push_back(c);
		c = fgetc(stdin);
	}
}

int main() {
	pairing_heap<ordered_set<int>> Q;
	std::string s;
	int k;
	while (scan(s),s[2] != 'd') {
		if (s[0] == 'i') {
			scanf("%d", &k);
			Q.push(k);
		}
		else {
			printf("%d\n", Q.top());
			Q.pop();
		}
	}
	return 0;
}


Measured memory_bytes: 33956