#include using namespace std; #include using namespace atcoder; using mint = atcoder::static_modint<998244353>; // using mint = atcoder::static_modint<1000000007>; using ld = long double; using ll = long long; #define mp(a,b) make_pair(a,b) #define rep(i,s,n) for(int i=s; i<(int)n; i++) using vl = vector; using vvl = vector; using vvvl = vector; using vvvvl = vector; const vector dx{1,0,-1,0},dy{0,1,0,-1}; struct v{ int val,cnt; }; v op(v L, v R){ if(L.valR.val)return R; else{ L.cnt+=R.cnt; return L; } } const int inf=1e9; v e(){return {inf,0};} v mapping(int F,v x){ x.val+=F; return x; } int comp(int F,int G){return F+G;} int id(){return 0;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,Q;cin >> n >> Q; lazy_segtree seg(n-1); rep(i,0,n-1)seg.set(i,{0,1}); vector> memo(Q); rep(q,0,Q){ int t;cin >> t; if(t==1){ int L,R;cin >> L >> R; L--; R--; memo[q]={L,R}; seg.apply(L,R,1); } else if(t==2){ int q;cin >> q; q--; auto [L,R]=memo[q]; seg.apply(L,R,-1); } else{ auto p=seg.all_prod(); int ans=1; if(p.val==0)ans+=p.cnt; cout << ans << "\n"; } // rep(i,0,n-1){ // cout << seg.get(i).val << " "; // } // cout << "\n"; } }