#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; set> S; S.insert({N + 1, N + 1}); auto add = [&](int l, int r){ auto it = S.lower_bound({l, -1}); if(it->second <= l && r <= it->first)return; while(it->second <= r){ l = min(l, it->second); r = max(r, it->first); S.erase(it); it = S.lower_bound({l, -1}); } S.insert({r, l}); }; auto same = [&](int l, int r){ if(l > r) swap(l, r); auto it = S.lower_bound({l, -1}); if(it->second <= l && r <= it->first) return true; return false; }; auto size = [&](int v){ auto it = S.lower_bound({v, -1}); if(it->second <= v && v <= it->first) return int(it->first - it->second + 1); return 1; }; int type, L, R, u, v; while(Q--){ cin >> type; if(type == 1){ cin >> L >> R; add(L, R); }else if(type == 2){ cin >> u >> v; cout << (same(u, v) ? 1 : 0) << '\n'; }else{ cin >> v; cout << size(v) << '\n'; } } }