# sada 2: staci si spravit sort po tom ako prestanu prichadzat
vplyv_rodiny = [ -1 for _ in range(200000) ]
usporiadal = False
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
        vplyv_rodiny[cr] = max( vplyv_rodiny[cr], cv )
        cakaren.append( (cid, cr) )
    if udalost[0] == 2:
        if not usporiadal:
            cakaren = [ (-vplyv_rodiny[cr], cr, cid) for cid, cr in cakaren ]
            cakaren.sort()
            kde = 0
            usporiadal = True
        if kde == len(cakaren):
            print(-1)
        else:
            print(cakaren[kde][2])
            kde += 1
