n = int(input()) dic = {} lst = [None] * 21 for i in range(1, n + 1): inp = input().split() if inp[0] == "0": lst[int(inp[1])] = i dic[i] = inp[2:] elif inp[0] == "1": b = inp[1] for j in range(21): if lst[j] != None and b in dic[lst[j]]: dic[lst[j]].remove(b) print(j) break else: print(-1) else: c = int(inp[1]) lst[c] = None