class HeapTree
	def initialize
		@node = []
	end

	private

	def swap(key)
		if  key < 0 
			return nil
		end
		if !left(key) && !right(key)
			return nil
		elsif left(key) && !right(key)
			if left(key) > @node[key]
				@node[key], @node[left_key(key)] =  @node[left_key(key)], @node[key]
				swap(left_key(key))
			end
		elsif right(key) && !left(key)
			if right(key) > @node[key]
				@node[key], @node[right_key(key)] =  @node[right_key(key)], @node[key]
				swap(right_key(key))
			end
		elsif @node[key] < left(key) && left(key) >= right(key)
			@node[key], @node[left_key(key)] =  @node[left_key(key)], @node[key]
			swap(left_key(key))
		elsif @node[key] < right(key) && right(key) >= left(key)
			@node[key], @node[right_key(key)] =  @node[right_key(key)], @node[key]
			swap(right_key(key))
		end
	end

	def from_leaf_swap(key)
		if key == 0
			nil
		end
		parent_key = (key-1)/2

		if @node[parent_key] < @node[key]
			@node[key], @node[parent_key] = @node[parent_key], @node[key]
			from_leaf_swap(parent_key)
		else
		end
	end

	def extract!
		priority_create
		num = @node[0]
		@node[0] = @node.pop
		return num
	end

	def insert!(num)
		@node << num
	end

	def left(key)
		@node[2*key+1]
	end

	def right(key)
		@node[2*key+2]
	end

	def left_key(key)
		2*key+1
	end

	def right_key(key)
		2*key+2
	end

	# ???????????¢?´¢
	def precedingOrderSearch(key, &func)
		if @node[key]
			func.call(key, @node[key])
			precedingOrderSearch(left(key), &func)
			precedingOrderSearch(right(key), &func)
		end
	end
	# ???????????¢?´¢
	def afterLineOrderSearch(key, &func)
		if @node[key]
			afterLineOrderSearch(left(key), &func)
			afterLineOrderSearch(right(key), &func)
			func.call(key, @node[key])
		end
	end
	#???????????¢?´¢
	def centerOrderSearch(node, &func)
		if @node[key]
			centerOrderSearch(left(key), &func)
			func.call(key, @node[key])
			centerOrderSearch(right(key), &func)
		end
	end

	public

	def insert(num)
		insert!(num)
	end

	def preceding_crawl(&func) #???hoge.precedingCrawl do |key, value| ??????????????????
		precedingOrderSearch(0, &func)
	end

 # ????????????
 def after_line_crawl(&func)
 	afterLineOrderSearch(0, &func)
 end

# ????????????
def center_crawl(&func)
	centerOrderSearch(0, &func)
end

def extract
	extract!
end

def priority_create
	i = 0
	loop{
		key = (@node.size.to_i-1)/2-i
		break if key < 0
		swap(key)
		i += 1
	}
end

def list
	return @node
end
end


ans = []
head = HeapTree.new
i = 1
loop {
	str = gets.to_s.chomp!
	if str == "extract"
		ans << head.extract
	elsif str == "end"
		break
	else
		str = str.split
		head.insert str[1].to_i
	end
}


ans.each do |v|
	puts v
end