#include #include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; assert(1 <= N && N <= 200000); assert(1 <= Q && Q <= 200000); atcoder::dsu uf(N); int l = 0, r = N - 1; while(Q--){ int type, u, v; cin >> type; if(type == 1){ cin >> u >> v; assert(1 <= u && u <= N); assert(1 <= v && v <= N); uf.merge(--u, --v); while(l != uf.leader(l)) l++; while(r != uf.leader(r)) r--; }else{ cin >> v; assert(1 <= v && v <= N); cout << (l == r ? -1 : (uf.same(--v, r) ? l + 1 : r + 1)) << '\n'; } } }