from sys import stdin class UnionFind(): def __init__(self, n): self.parent_or_size = [-1] * n def leader(self, x): while self.parent_or_size[x] >= 0: x = self.parent_or_size[x] return 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: if l == r: print(-1) elif uf.same(l, query[1] - 1): print(r + 1) else: print(l + 1)