#include using namespace std; struct UnionFind { vector par; vector size; UnionFind(int n) { par.resize(n); size.resize(n,1); for(int i = 0; i < n; i++) { par[i] = i; } } int find(int x) { if(par[x] == x) { return x; } return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int consize(int x) { return size[find(x)]; } bool unite(int x, int y) { x = find(x); y = find(y); if(x == y) { return false; } if(size[x] > size[y]) { swap(x,y); } par[x] = y; size[y] += size[x]; return true; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N >> Q; UnionFind uf(N); setst; for(int i = 1; i <= N; i++) st.insert(i); while(Q--) { int f; cin >> f; if(f == 1) { int u,v; cin >> u >> v; u--; v--; if(!uf.same(u,v)) { st.erase(uf.find(u)); st.erase(uf.find(v)); uf.unite(u,v); st.insert(uf.find(u)); } } else { int v; cin >> v; v--; if(uf.consize(v) == N) { cout << -1 << "\n"; } else { st.erase(uf.find(v)); cout << *st.begin()+1 << "\n"; st.insert(uf.find(v)); } } } }