#!/usr/bin/env ruby
# encoding: UTF-8

# min???????????即?????????????????????????????????
# node[i]??????node???min???????????即??則????????????????????????
def minHeapify(heap_tree, i)
  heap_size = heap_tree.size
  i_l = 2 * i + 1
  i_r = 2 * i + 2
  smallest = i

  if i_l <= heap_size
    case heap_tree[i_l] <=> heap_tree[i]
    when -1
      smallest = i_l
    end
  end

  if i_r <= heap_size
    case heap_tree[i_r] <=> heap_tree[smallest]
    when -1
      smallest = i_r
    end
  end

  if smallest != i
    heap_tree[i], heap_tree[smallest] = heap_tree[smallest], heap_tree[i]
    minHeapify(heap_tree, smallest)
  end
end

# max???????????即?????????????????????????????????
# node[i]??????node???max???????????即??則????????????????????????
def maxHeapify(heap_tree, i)
  heap_size = heap_tree.size
  #i_p = (i - 1) / 2
  i_l = 2 * i + 1
  i_r = 2 * i + 2
  largest = i

  if i_l <= heap_size - 1
    case heap_tree[i_l] <=> heap_tree[i]
    when 1
      largest = i_l
    end
  end

  if i_r <= heap_size - 1
    case heap_tree[i_r] <=> heap_tree[largest]
    when 1
      largest = i_r
    end
  end

  if largest != i
    heap_tree[i], heap_tree[largest] = heap_tree[largest], heap_tree[i]
    maxHeapify(heap_tree, largest)
  end
end

# max???????????即???????卒????????????????
def maxHeapInsert(heap, x)
  heap.push(x)
  i = heap.size - 1
  i_p = (i - 1) / 2
  while i > 0 and heap[i_p] < heap[i]
    heap[i_p], heap[i] = heap[i], heap[i_p]
    i = i_p
    i_p = (i - 1) / 2
  end
end

# max???????????即????????????????????????
def maxHeapExtract(heap)
  result = heap.shift
  heap.unshift(heap.pop)
  maxHeapify(heap, 0)
  return result
end

def buildMaxHeap(heap_tree)
  ((heap_tree.size - 1) / 2).downto(0) do |i|
    maxHeapify(heap_tree, i)
  end
end

heap = []
while line = gets
  cmd = line.chomp.split(" ")
  case cmd[0]  
  when "insert"
    maxHeapInsert(heap, cmd[1].to_i)
  when "extract"
    puts maxHeapExtract(heap)
  when "end"
    break
  end
  if heap.size >= 1000
    puts ">= 600"
  end
end