class UnionFind(): def __init__(self, n): self.parent_or_size = [-1] * n def leader(self, x): if self.parent_or_size[x] < 0: return x else: self.parent_or_size[x] = self.leader(self.parent_or_size[x]) return self.parent_or_size[x] def same(self, x, y): return self.leader(x) == self.leader(y) def merge(self, x, y): rx = self.leader(x) ry = self.leader(y) if rx == ry: return False if self.parent_or_size[rx] > self.parent_or_size[ry]: rx, ry = ry, rx self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return True def size(self, x): return -self.parent_or_size[self.leader(x)] N, Q = map(int, input().split()) uf = UnionFind(N) l, r = 0, N - 1 for _ in range(Q): query = list(map(int, input().split())) t = query[0] if t == 1: uf.merge(query[1] - 1, query[2] - 1) while l != uf.leader(l): l += 1 while r != uf.leader(r): r -= 1 else: if uf.size(0) == N: print(-1) elif uf.same(l, query[1] - 1): print(r + 1) else: print(l + 1)