#include<cstdio>
struct ain{
int b,e,tot;
}aint[450005];
int lazy[450005];
int build(int nod,int st,int dr){
aint[nod].b=dr-st+1;
aint[nod].e=dr-st+1;
aint[nod].tot=dr-st+1;
int mij=(st+dr)/2;
if (st!=dr)
build(nod*2,st,mij),build(nod*2+1,mij+1,dr);}
int update(int nod,int st,int dr,int x,int y,int val){
if (lazy[nod]==1){
aint[nod].b=dr-st+1;
aint[nod].e=dr-st+1;
aint[nod].tot=dr-st+1;
if (st!=dr)
lazy[2*nod]=1,lazy[2*nod+1]=1;
lazy[nod]=0;}
if (lazy[nod]==-1){
aint[nod].b=0;
aint[nod].e=0;
aint[nod].tot=0;
if (st!=dr)
lazy[2*nod]=-1,lazy[2*nod+1]=-1;
lazy[nod]=0;}
if (st>dr || st>y || dr<x)
return 0;
if (st>=x && dr<=y){
if (val==1)
aint[nod].b=dr-st+1,aint[nod].e=dr-st+1,aint[nod].tot=dr-st+1;
else
aint[nod].b=0,aint[nod].e=0,aint[nod].tot=0;
if (st!=dr)
lazy[2*nod]=lazy[2*nod+1]=val;
return 0;}
int mij=(st+dr)/2;
update(nod*2,st,mij,x,y,val);
update(nod*2+1,mij+1,dr,x,y,val);
if (aint[nod*2].b==mij-st+1)
aint[nod].b=aint[nod*2].b+aint[nod*2+1].b;
else
aint[nod].b=aint[nod*2].b;
if (aint[nod*2+1].e==dr-mij)
aint[nod].e=aint[nod*2+1].e+aint[nod*2].e;
else
aint[nod].e=aint[nod*2+1].e;
aint[nod].tot=aint[nod*2].e+aint[nod*2+1].b;}
int main(){
freopen("hotel.in","r",stdin);
freopen("hotel.out","w",stdout);
int n,p,i,tip,x,y;
scanf("%d%d",&n,&p);
build(1,1,n);
for(i=1;i<=p;i++){
scanf("%d",&tip);
if (tip==1){
scanf("%d%d",&x,&y);
update(1,1,n,x,x+y-1,-1);}
if (tip==2){
scanf("%d%d",&x,&y);
update(1,1,n,x,x+y-1,1);}
if (tip==3)
printf("%d\n",aint[1].tot);}
return 0;}