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)] from collections import deque 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=deque() 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: xx=x+1 if xx == n+1: xx = 1 print(xx) else: if uf.size(fx) == n: print(-1) elif len(nots) > 0: for i in nots: print(i) break else: while len(lis)>1: if fx == lis[-1]: lis.appendleft(lis.pop()) else: if fx == uf.find(lis[-1]): lis.pop() else: print(lis[-1]) break