from sys import stdin 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 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, ry = self.leader(x), self.leader(y) if rx == ry: return if self.parent_or_size[rx] > self.parent_or_size[ry]: rx, ry = ry, rx self.parent_or_size[rx] += self.parent_or_size[ry] self.parent_or_size[ry] = rx N, Q = map(int, stdin.readline().split()) uf = UnionFind(N) l, r = 0, N - 1 for _ in range(Q): query = list(map(int, stdin.readline().split())) if query[0] == 1: uf.merge(query[1] - 1, query[2] - 1) while l != uf.leader(l): l += 1 while r != uf.leader(r): r -= 1 else: print(-1 if l == r else l + 1 if uf.same(query[1] - 1, r) else r + 1)