#include <cstdio>
#define buffSize 1048576
#define TSize 262145
using namespace std;
char buff[buffSize];
bool ok=true;
int ind;
struct tree
{
int L,R,free;
}T[TSize];
inline void read(int &x)
{
if(ok)
{
ok=false;
ind=0;
fread(buff,1,buffSize,stdin);
}
for(x=0;'0'<=buff[ind]&&buff[ind]<='9';)
{
x*=10;
x+=buff[ind]-'0';
if(++ind==buffSize)
{
ind=0;
fread(buff,1,buffSize,stdin);
}
}
for(;'0'>buff[ind]||buff[ind]>'9';)
if(++ind==buffSize)
{
ind=0;
fread(buff,1,buffSize,stdin);
}
}
inline void update(int nod,int L,int R,int a,int b,int val)
{
if(L==R&&a<=L&&R<=b)
{
T[nod].free=1-val;
T[nod].L=1-val;
T[nod].R=1-val;
return;
}
int M=(L+R)>>1;
if(a<=M) update(nod<<1,L,M,a,b,val);
if(b>M) update((nod<<1)+1,M+1,R,a,b,val);
T[nod].L=T[nod<<1].L;
if(T[nod].L==M-L+1) T[nod].L+=T[(nod<<1)+1].L;
T[nod].R=T[(nod<<1)+1].R;
if(T[nod].R==R-M) T[nod].R+=T[nod<<1].R;
T[nod].free=T[nod<<1].R+T[(nod<<1)+1].L;
if(T[nod<<1].free>T[nod].free) T[nod].free=T[nod<<1].free;
if(T[(nod<<1)+1].free>T[nod].free) T[nod].free=T[(nod<<1)+1].free;
}
int main()
{
int N,P,a,b,c;
freopen("hotel.in","r",stdin);
read(N);
read(P);
update(1,1,N,1,N,0);
freopen("hotel.out","w",stdout);
for(;P--;)
{
read(c);
if(c==3)
{
printf("%d\n",T[1].free);
continue;
}
if(c==2) c=0;
read(a);
read(b);
b+=a-1;
update(1,1,N,a,b,c);
}
return 0;
}