#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace atcoder; using namespace std; using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template ostream &operator<<(ostream &os,const pair&p){ os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template istream &operator>>(istream &is,vector &a){ for(auto &i:a)is>>i; return is; } #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() ll myceil(ll a,ll b){return (a+b-1)/b;} int main(){ int n,q; cin>>n>>q; vector>id(n); rep(i,n)id[i].push_back(i); dsu uf(n); while(q--){ int t; cin>>t; if(t==1){ int u,v; cin>>u>>v; u--,v--; if(uf.same(u,v))continue; u=uf.leader(u),v=uf.leader(v); uf.merge(u,v); int l=uf.leader(u); if(l!=u)swap(u,v); for(auto i:id[v])id[u].push_back(i); //sort(all(id[u])); } else{ int u; cin>>u; u--; u=uf.leader(u); if(id[u].size()==n){ cout<<-1<1){ int mid=(l+r)/2; if(lower_bound(all(id[u]),mid)-id[u].begin()==mid)l=mid; else r=mid; } cout<