#include<bits/stdc++.h>
using namespace std;
int n,q,a[500100],B,is[500100],L[810],R[810];
vector<int>g[810];
int mx[810];
#define pb push_back
int fa[500010],ab[501000],wh[501000];
int F(int x){
if(x==fa[x])return x;
return fa[x]=F(fa[x]);
}
void cg(int e){
if(g[e].empty())return;
for(int i=L[e];i<=R[e];i++){
if(!ab[a[i]])ab[a[i]]=i,fa[i]=i,wh[i]=a[i];
else fa[i]=ab[a[i]];
}
for(int x:g[e]){
if(ab[x]&&ab[x+1])fa[ab[x]]=ab[x+1],ab[x]=0;
else if(ab[x])ab[x+1]=ab[x],ab[x]=0,wh[ab[x+1]]=x+1;
}
for(int i=L[e];i<=R[e];i++)a[i]=wh[F(i)];
for(int i=L[e];i<=R[e];i++)ab[wh[i]]=0;
g[i].clear();
}
int main(){
scanf("%d%d",&n,&q);B=sqrt(n);
for(int i=1;i<=n;i++)is[i]=(i-1)/B+1;
for(int i=1;i<=is[n];i++){
L[i]=(i-1)*B+1,R[i]=min(n,i*B);
}
for(int ii=1,ty,l,r,z;ii<=q;ii++){
scanf("%d%d%d",&ty,&l,&r);
int lp=is[l],rp=is[r];
cg(lp);if(lp<rp)cg(rp);
if(ty==1){
scanf("%d",&z);
if(lp!=rp){
for(int i=l;i<=R[lp];i++)if(a[i]==z)a[i]=z+1,mx[lp]=max(mx[lp],z+1);
for(int i=L[rp];i<=r;i++)if(a[i]==z)a[i]=z+1,mx[rp]=max(mx[rp],z+1);
}
else{for(int i=l;i<=r;i++)if(a[i]==z)a[i]=z+1,mx[lp]=max(mx[lp],z+1);}
for(int i=lp+1;i<rp;i++){
g[i].pb(z);
if(mx[i]==z)mx[i]=z+1;
}
}
else{
int ans=0;
if(lp!=rp){
for(int i=l;i<=R[lp];i++)ans=max(ans,a[i]);
for(int i=L[rp];i<=r;i++)ans=max(ans,a[i]);
}
else{for(int i=l;i<=r;i++)ans=max(ans,a[i]);}
for(int i=lp+1;i<rp;i++)ans=max(ans,mx[i]);
printf("%d\n",ans);
}
}
return 0;
}