n = int(input()) pos = [{} for _ in range(21)] for _ in range(n): t, *Q = input().split() if t == "0": n, m, *A = Q n = int(n) for a in A: pos[n][a] = pos[n].get(a, 0) + 1 elif t == "1": ng = True b = Q[0] for i in range(1, 21): if pos[i].get(b, 0) > 0: print(i) pos[i][b] -= 1 ng = False break if ng: print(-1) else: c = int(Q[0]) pos[c] = {}