import java.util.Scanner; import java.util.Arrays; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int Q = sc.nextInt(); UnionFind uf = new UnionFind(N+1); while(Q-->0){ int q = sc.nextInt(); if(q==1){ int u = sc.nextInt(); int v = sc.nextInt(); uf.unite(u,v); } else{ int v = sc.nextInt(); int ans = uf.unUnitePoint(v); if(ans>N) ans = -1; System.out.println(ans); } } } } class UnionFind{ int[] par,unUnite; UnionFind(int N){ par = new int[N]; unUnite = new int[N]; Arrays.fill(par,-1); Arrays.fill(unUnite,1); unUnite[1] = 2; } int root(int x){ if(par[x]==-1) return x; return par[x] = root(par[x]); } void unite(int x,int y){ int rootX = root(x); int rootY = root(y); if(rootX==rootY) return; par[rootY] = rootX; check(rootY); check(rootX); } void check(int x){ int root = root(x); while(unUnite[root]