#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif #include void solve() { int N, Q; cin >> N >> Q; atcoder::dsu uf(N); vector memo(N); while(Q--) { int t; cin >> t; if(t == 1) { int u, v; cin >> u >> v; u--; v--; uf.merge(u, v); }else { int u; cin >> u; u--; int& cur = memo[uf.leader(u)]; while(cur < N && uf.same(u, cur)) cur++; if(cur != N) { cout << cur + 1 << endl; }else { cout << -1 << endl; } }//??? } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while(tt--) { solve(); } }