N = int(input()) from collections import defaultdict d = [defaultdict(int) for _ in range(20)] for _ in range(N): l = input().split() l[0] = int(l[0]) if l[0] == 0: n = int(l[1]) m = int(l[2]) n -= 1 d[n] = defaultdict(int) for v in l[3:]: d[n][v] += 1 elif l[0] == 1: b = l[1] flag = False for i in range(20): if b in d[i]: print(i + 1) d[i][b] -= 1 if d[i][b] == 0: del d[i][b] flag = True break if flag == False: print(-1) else: c = int(l[1]) d[c-1] = defaultdict(int)