import random class UnionFindTree: def __init__(self, n): self.par = [-1] * n self.rank = [0] * n self.sz = [1] * n def root(self, v): if self.par[v] == -1: return v self.par[v] = self.root(self.par[v]) return self.par[v] def same(self, v1, v2): return self.root(v1) == self.root(v2) def size(self, v): return self.sz[self.root(v)] def unite(self, v1, v2): root1, root2 = self.root(v1), self.root(v2) if root1 == root2: return if self.rank[root1] < self.rank[root2]: root1, root2 = root2, root1 self.par[root2] = root1 if self.rank[root1] == self.rank[root2]: self.rank[root1] += 1 self.sz[root1] += self.sz[root2] n, q = map(int, input().split()) uf = UnionFindTree(n) for i in range(q): query = list(map(int, input().split())) if query[0] == 1: u, v = query[1] - 1, query[2] - 1 uf.unite(u, v) else: v = query[1] - 1 if uf.size(v) == n: print(-1) else: while True: u = random.randrange(0, n) if not uf.same(u, v): print(u + 1) break