#include using namespace std; constexpr int INPUT_MAX=200005; int rt[INPUT_MAX]; int sz[INPUT_MAX]; int getroot(int n){ if(rt[n]==-1)return n; return rt[n]=getroot(rt[n]); } void unite(int a,int b){ a=getroot(a),b=getroot(b); if(a!=b){ rt[a]=b; sz[b]+=sz[a]; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); fill(rt,rt+INPUT_MAX,-1); fill(sz,sz+INPUT_MAX,1); int N,Q; cin>>N>>Q; int NG=Q; vector>output; for(int i=0;i>p; if(p==1){ int a,b; cin>>a>>b; --a,--b; if(getroot(a)!=getroot(b)&&sz[getroot(a)]+sz[getroot(b)]==N){ NG=i; }else{ unite(a,b); } }else{ int v; cin>>v; output.push_back({i,v-1}); } } arrayrrr={-1,-1}; for(int i=0;i=NG){ cout<<"-1\n"; }else{ cout<<(getroot(j)==rrr[0]?rrr[1]:rrr[0])+1<<'\n'; } } }