# sada 5: staci si vsetkych drzat v halde podla vplyvu
# sada 3: staci si vsetkych drzat v halde podla rodiny a potom id
# toto riesenie robi naraz oboje, takze vyriesi obe tieto sady
from heapq import heappush, heappop
cakaren = []
next_id = 0
while True:
    udalost = [ int(_) for _ in input().split() ]
    if udalost[0] == 0: break
    if udalost[0] == 1:
        cid, cv, cr, next_id = next_id, udalost[1], udalost[2], next_id+1
        heappush(cakaren, (-cv, cr, cid) )
    if udalost[0] == 2:
        if cakaren == []:
            print(-1)
        else:
            print(heappop(cakaren)[2])

