#include using namespace std ; #define int long long const int N = 2e5 + 5 ; int n , q , op , u , v , k , a[N] , fa[N] ; set st[N] ; int find(int x) { if(fa[x] == x) return x ; return fa[x] = find(fa[x]) ; } signed main() { ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; // freopen(".in" , "r" , stdin) ; // freopen(".out" , "w" , stdout) ; cin >> n >> q ; for(int i = 1 ; i <= n ; i ++) { fa[i] = i ; st[i].insert(i) ; } while(q --) { cin >> op ; if(op == 1) { cin >> u >> v ; int fu = find(u) , fv = find(v) ; if(fu == fv) continue ; if(st[fu].size() > st[fv].size()) swap(st[fu] , st[fv]) ; for(auto i : st[fu]) st[fv].insert(i) ; st[fu].clear() ; fa[fu] = fv ; } if(op == 2) { cin >> v >> k ; int fv = find(v) ; if(st[fv].size() < k) { cout << -1 << "\n" ; continue ; } auto it = st[fv].end() ; for(int i = 1 ; i <= k ; i ++) it -- ; cout << (*it) << "\n" ; } } return 0 ; } /** * @runId: 63562 * @language: C++ With O2 * @author: ??? * @submitTime: 2026-05-06 15:54:28 */