N = int(input()) List = [[] for _ in range(21)] for _ in range(N): temp = [str(t) for t in input().split()] if temp[0] == "0": List[int(temp[1])] += temp[3:] elif temp[0] == "1": flag = True for i in range(1, 21): if temp[1] in List[i]: print(i) List[i].remove(temp[1]) flag = False break if flag: print(-1) else: List[int(temp[1])] = []