from collections import deque class Union_Find(): def __init__(self, N): self.size = [1] * N self.parent = [0] * N for i in range(N): self.parent[i] = i def find(self, x): if self.parent[x] == x: return x self.parent[x] = self.find(self.parent[x]) return self.parent[x] def is_same(self, x, y): return self.find(x) == self.find(y) def unit(self, x, y): x, y = self.find(x), self.find(y) if x == y: return x if self.size[x] < self.size[y]: x, y = y, x self.size[x] += self.size[y] self.parent[y] = x return x N, Q = map(int, input().split()) UF = Union_Find(N) dq = deque() for i in range(N): dq.append(i) used = [False] * N for i in range(Q): q = list(map(int, input().split())) if q[0] == 1: q[1] -= 1 q[2] -= 1 used[UF.find(q[1])] = True used[UF.find(q[2])] = True used[UF.unit(q[1], q[2])] = False while used[dq[0]]: dq.popleft() dq.rotate() while used[dq[0]]: dq.popleft() else: q[1] -= 1 if len(dq) == 1: print(-1) elif UF.is_same(dq[0], q[1]): print(dq[-1] + 1) else: print(dq[0] + 1)