#include #include using namespace std; int main() { int n, q; cin >> n >> q; atcoder::dsu uf(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--; if (uf.size(u) == n){ cout << -1 << endl; } else { int l = 0, r = n; while (r - l > 1){ int mid = (l + r) / 2; if (uf.leader(mid) != uf.leader(u)){ l = mid; } else { r = mid; } } cout << l + 1 << endl; } } } }