# coding: utf-8 # Your code here! N,Q=map(int,input().split()) par = [i for i in range(N+1)] rank = [0]*(N+1) def find(x): if par[x] == x: return x else: par[x] = find(par[x]) #経路圧縮 return par[x] def same(x,y): return find(x) == find(y) def unite(x,y): x = find(x) y = find(y) if x == y: return 0 if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x]==rank[y]:rank[x]+=1 is_par=set([i for i in range(N)]) def recog(n): if n in is_par: if find(n)!=n: is_par.remove(n) else: if find(n)==n: is_par.add(n) l,r=0,N-1 for _ in range(Q): q=input().split() if q[0]=="1": u,v=int(q[1])-1,int(q[2])-1 unite(u,v) while l!=find(l): l+=1 while r!=find(r): r-=1 else: v=int(q[1])-1 print(-1 if l==r else l+1 if same(v,r) else r+1)