#include using namespace std; int main(){ int N, Q; cin >> N >> Q; vector t(Q), U(Q), V(Q); for (int i = 0; i < Q; i++){ cin >> t[i]; if (t[i] == 1){ cin >> U[i] >> V[i]; U[i]--; V[i]--; } if (t[i] == 2){ cin >> V[i]; V[i]--; } } int tv = Q + 1, fv = -1; while (tv - fv > 1){ int mid = (tv + fv) / 2; vector> E(N); for (int i = 0; i < mid; i++){ if (t[i] == 1){ E[U[i]].push_back(V[i]); E[V[i]].push_back(U[i]); } } vector used(N, false); used[0] = true; queue q; q.push(0); while (!q.empty()){ int v = q.front(); q.pop(); for (int w : E[v]){ if (!used[w]){ used[w] = true; q.push(w); } } } if (used == vector(N, true)){ tv = mid; } else { fv = mid; } } vector> E(N); for (int i = 0; i < fv; i++){ if (t[i] == 1){ E[U[i]].push_back(V[i]); E[V[i]].push_back(U[i]); } } vector c(N, -1); int cnt = 0; vector p; for (int i = 0; i < N; i++){ if (c[i] == -1){ c[i] = cnt; queue q; q.push(i); while (!q.empty()){ int v = q.front(); q.pop(); for (int w : E[v]){ if (c[w] == -1){ c[w] = cnt; q.push(w); } } } p.push_back(i); cnt++; } } for (int i = 0; i < Q; i++){ if (t[i] == 2){ if (i >= tv){ cout << -1 << endl; } else if (c[V[i]] == 0){ cout << p[1] + 1 << endl; } else { cout << p[0] + 1 << endl; } } } }