import sys input = sys.stdin.readline def main(): N, Q = map(int, input().split()) uf = UnionFind(N) ans = [] total = set(range(N)) for _ in range(Q): query = list(map(int, input().split())) if query[0] == 1: u, v = query[1:] u, v = u - 1, v - 1 uf.union(u, v) else: v = query[1] - 1 u = uf.find(v) res = total - uf.groups[u] ans.append(res.pop() + 1 if res else -1) print(*ans, sep='\n') class UnionFind: def __init__(self, n): self.parent = [-1] * n self.groups = dict() for i in range(n): self.groups[i] = {i} def find(self, x): if self.parent[x] < 0: return x self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.parent[y] < self.parent[x]: x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x self.groups[x] |= self.groups[y] del self.groups[y] def same(self, x, y): return self.find(x) == self.find(y) main()