N=input() list=[None]*20 for i in range(int(N)): data=input().split() if data[0]=='0': list[int(data[1])-1]=data[3:] elif data[0]=='1': eat=False for j in range(20): if list[j] != None and data[1] in list[j]: list[j].remove(data[1]) print(j+1) eat=True break if eat==False: print(-1) else: list[int(data[1]) -1] =None