#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vd = vector; using vs = vector; using pii = pair; using pll = pair; using pdd = pair; using vpii = vector; using vpll = vector; using vpdd = vector; const int inf = (1 << 30) - 1; const ll INF = 1LL << 60; const int MOD = 1000000007; //const int MOD = 998244353; struct UnionFind { vector par; vector sizes; UnionFind(int n) : par(n), sizes(n, 1) { for (int i = 0; i < n; i++) par[i] = i; } int root(int x) { if (x == par[x]) return x; return par[x] = root(par[x]); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (sizes[x] < sizes[y]) swap(x, y); par[y] = x; sizes[x] += sizes[y]; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return sizes[root(x)]; } }; int main() { int n, q; cin >> n >> q; UnionFind uf(n); for (int i = 0; i < q; i++) { int t, u, v; cin >> t; if (t == 1) { cin >> u >> v; u--; v--; uf.unite(u, v); } else { cin >> v; v--; int r = uf.root(v); if (uf.size(r) == n) { cout << -1 << endl; } else { for (int j = 0; j < n; j++) { if (uf.root(j) != r) { cout << j + 1 << endl; break; } } } } } return 0; }