#include<iostream>
#define lc p<<1
#define rc p<<1|1
#define int long long
using namespace std;
const int N=2e5+10;
struct tree
{
int l,r,sum,lmax,rmax,ans,lazy;
}tr[N<<2];
int n,m;
void build(int p,int l,int r)
{
if(l==r)
{
tr[p]={l,r,1,0,0,0,0};
return;
}
int mid=(l+r)/2;
build(lc,l,mid);
build(rc,mid+1,r);
tr[p]={l,r,r-l+1,0,0,0,0};
}
void pushup(int p)
{
tr[p].sum=tr[lc].sum+tr[rc].sum;
if(tr[lc].lmax==tr[lc].r-tr[lc].l+1)tr[p].lmax=tr[lc].lmax+tr[rc].lmax;
else tr[p].lmax=tr[lc].lmax;
if(tr[rc].rmax==tr[rc].r-tr[rc].l+1)tr[p].rmax=tr[rc].rmax+tr[lc].rmax;
else tr[p].rmax=tr[rc].rmax;
tr[p].ans=max(tr[lc].lmax,max(tr[rc].rmax,tr[lc].rmax+tr[rc].lmax));
}
void d1(int p)
{
tr[p].ans=tr[p].lmax=tr[p].rmax=tr[p].r-tr[p].l+1;
tr[p].sum=0;
tr[p].lazy=1;
}
void d2(int p)
{
tr[p].ans=tr[p].lmax=tr[p].rmax=0;
tr[p].sum=tr[p].r-tr[p].l+1;
tr[p].lazy=2;
}
void pushdown(int p)
{
if(tr[p].lazy==1)d1(lc),d1(rc);
if(tr[p].lazy==2)d2(lc),d2(rc);
tr[p].lazy=0;
}
void update(int p,int x,int y,int z)
{
if(tr[p].l>=x&&tr[p].r<=y)
{
if(z==1)d1(p);
if(z==2)d2(p);
return;
}
pushdown(p);
int mid=(tr[p].l+tr[p].r)/2;
if(x<=mid)update(lc,x,y,z);
if(y>mid)update(rc,x,y,z);
pushup(p);
}
int q0(int p,int x,int y)
{
if(tr[p].l>=x&&tr[p].r<=y)return tr[p].sum;
pushdown(p);
int mid=(tr[p].l+tr[p].r)/2;
int ans=0;
if(x<=mid)ans+=q0(lc,x,y);
if(y>mid)ans+=q0(rc,x,y);
return ans;
}
int q1(int p,int x,int y)
{
if(tr[p].l>=x&&tr[p].r<=y)return tr[p].ans;
pushdown(p);
int mid=(tr[p].l+tr[p].r)/2;
if(y<=mid)return q1(lc,x,y);
if(x>mid)return q1(rc,x,y);
else return max(max(q1(lc,x,y),q1(rc,x,y)),min(tr[lc].rmax,mid-x+1)+min(tr[rc].lmax,y-mid));
}
void erfen(int l0,int r0,int l1,int r1)
{
int sum=q0(1,l0,r0);
if(!sum)return;
update(1,l0,r0,1);
int l=l1,r=r1;
while(l<=r){
int mid=(l+r)>>1;
if(mid-l1+1-q0(1,l1,mid)<=sum)l=mid+1;
else r=mid-1;
}
update(1,l1,l-1,2);
}
signed main()
{
cin>>n>>m;
build(1,1,n);
for(int i=1;i<=m;i++)
{
int op;
cin>>op;
if(op==0)
{
int l,r;
cin>>l>>r;
update(1,l,r,1);
}
else if(op==1)
{
int l,r,l1,r1;
cin>>l>>r>>l1>>r1;
erfen(l,r,l1,r1);
}
else{
int l,r;
cin>>l>>r;
cout<<q1(1,l,r)<<endl;
}
}
return 0;
}