#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(2 * Q + 1); 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[2 * i] = get<1>(query[i]); ca[2 * i + 1] = 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]; u = lower_bound(ca.begin(), ca.end(), u) - ca.begin(); if(v) v = lower_bound(ca.begin(), ca.end(), v) - ca.begin(); if(type <= 2) seg.apply(u, v, 2 - type); else if(type == 3){ if(u > v) swap(u, v); cout << seg.prod(u, v) << '\n'; }else{ 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'; } } }