""" UnionFind """ class UnionFind(): def __init__(self, N): self.N = N self.parents = [-1] * N def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) N,Q = map(int, input().split()) vertex = set([i for i in range(N)]) UF = UnionFind(N) for q in range(Q): INPUT = list(map(int, input().split())) if INPUT[0] == 1: UF.union(INPUT[1]-1, INPUT[2]-1) if UF.find(INPUT[1]-1) == INPUT[1]-1: vertex.discard(INPUT[2]-1) else: vertex.discard(INPUT[1]-1) else: if len(vertex) == 1: print(-1) else: v1,v2 = vertex.pop(), vertex.pop() if v1 == UF.find(INPUT[1]-1): print(v2+1) else: print(v1+1) vertex.add(v1) vertex.add(v2)