class UF: def __init__(self,n): self.p = [-1]*n; self.i = set(range(n)) def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.i.remove(y); self.p[y] = x def s(self,x,y): return self.f(x) == self.f(y) n,q = map(int,input().split()) uf = UF(n) for _ in range(q): p = list(map(int,input().split())) if p[0]==1: uf.u(p[1]-1,p[2]-1) if p[0]==2: if len(uf.i)==1: print(-1); continue i = uf.f(p[1]-1) for j in uf.i: if i!=j: print(j+1); break