#include using namespace std; using S = int; S e(){return 1;} S op(S lhs, S rhs){return min(lhs, rhs);} using F = int; S mapping(F f, S x){return f == -1 ? x : f;} F composition(F f, F g){return f == -1 ? g : f;} F id(){return -1;} int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q, type, u, v, L, R; cin >> N >> Q; vector ca = {1, N}; vector> query(Q); for(int i = 0; i < Q; i++){ cin >> get<0>(query[i]) >> get<1>(query[i]); if(get<0>(query[i]) != 4) cin >> get<2>(query[i]); ca.emplace_back(get<1>(query[i])); ca.emplace_back(get<2>(query[i])); } sort(ca.begin(), ca.end()); ca.erase(unique(ca.begin(), ca.end()), ca.end()); atcoder::lazy_segtree seg(vector(ca.size(), 0)); for(int i = 0; i < Q; i++){ tie(type, u, v) = query[i]; if(type <= 2){ L = lower_bound(ca.begin(), ca.end(), u) - ca.begin(); R = lower_bound(ca.begin(), ca.end(), v) - ca.begin(); seg.apply(L, R, 2 - type); }else if(type == 3){ u = lower_bound(ca.begin(), ca.end(), u) - ca.begin(); v = lower_bound(ca.begin(), ca.end(), v) - ca.begin(); if(u > v) swap(u, v); cout << seg.prod(u, v) << '\n'; }else{ u = lower_bound(ca.begin(), ca.end(), u) - ca.begin(); L = seg.min_left(u, [](int v){return v != 0; }); R = seg.max_right(u, [](int v){return v != 0; }); cout << ca[R] - ca[L] + 1 << '\n'; } } }