#include #include #include #include #include #include #include #include #include #include using namespace std; struct UnionFind { vector par; vector siz; UnionFind(long long N) : par(N), siz(N) { for(long long i = 0; i < N; i++){ par[i] = i; siz[i] = 1; } } long long root(long long x) { if (par[x] == x) return x; return par[x] = root(par[x]); } long long unite(long long x, long long y) { long long rx = root(x); long long ry = root(y); if (rx == ry) return rx; if (siz[rx] > siz[ry]) swap(rx, ry); par[rx] = ry; siz[ry] += siz[rx]; return ry; } bool same(long long x, long long y) { long long rx = root(x); long long ry = root(y); return rx == ry; } long long size(long long x){ return siz[root(x)]; } }; int main(){ long long N, Q, t, x, y, xp, yp; cin >> N >> Q; UnionFind tree(N+1); set st; for (int i=1; i<=N; i++) st.insert(i); for (int i=0; i> t; if (t == 1){ cin >> x >> y; xp = tree.root(x); yp = tree.root(y); if (xp == yp) continue; tree.unite(xp, yp); if (tree.root(xp) == yp) swap(xp, yp); st.erase(yp); } else{ cin >> x; xp = tree.root(x); if (st.size() == 1) cout << -1 << endl; else{ if (*st.begin() == xp) cout << *st.rbegin() << endl; else cout << *st.begin() << endl; } } } return 0; }