class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] n,q= map(int,input().split()) nots = set() uf = UnionFind(n+1) for i in range(1,n+1): nots.add(i) s=set() lis=[] for i in range(q): t = list(map(int,input().split())) if t[0] == 1: x,y=t[1],t[2] if x > y: x,y = y,x nots.discard(x) nots.discard(y) uf.union(x,y) fx=uf.find(x) if fx not in s: s.add(x) lis.append(x) else: x=t[1] fx=uf.find(x) if fx not in s: print(x%(n+1) + 1) else: if uf.size(fx) == n: print(-1) elif len(nots) > 0: for i in nots: print(i) break else: if lis[0] != fx: print(lis[0]) else: print(lis[-1])