class HeapTree
	def initialize
		@node = []
	end

	private

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

	def extract!
		num = @node[0]
		@node[0] = @node.pop
		swap(@node[@node.length-1])
		return num
	end

	def insert!(num)
		@node << num
		swap(@node.length.to_i - 1)
	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 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