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 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[rx] += self.parent_or_size[ry] self.parent_or_size[ry] = rx return True 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: if l == r: print(-1) elif uf.same(l, query[1] - 1): print(r + 1) else: print(l + 1)