#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 del = [&](int l, int r){ auto it = S.lower_bound({l + 1, -1}); while(it->second < r){ int l0, r0, l1, r1; tie(r0, l0) = *it; l1 = l0, r1 = r0; S.erase(it); l0 = min(l0, l); r0 = min(r0, l); l1 = max(l1, r); r1 = max(r1, r); if(l0 < r0) S.insert({r0, l0}); if(l1 < r1) S.insert({r1, l1}); it = S.lower_bound({l + 1, -1}); } }; 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 <= 2){ cin >> L >> R; if(type == 1) add(L, R); else del(L, R); }else if(type == 3){ cin >> u >> v; cout << (same(u, v) ? 1 : 0) << '\n'; }else{ cin >> v; cout << size(v) << '\n'; } } }