n=int(input()) Q=int(input()) que=[] for _ in range(Q): que+=[list(map(int,input().split()+["0","0"]))[:3]] op=lambda x,y:(min(x[0],y[0]),x[1]*(x[0]<=y[0])+y[1]*(y[0]<=x[0])) B=1000 st1=[0]*B*B st2=[(0,B) for i in range(B)] lt=[0]*B X=10**10 for t,p1,p2 in que: l,r=0,n-2 if t==1: l,r=p1-1,p2-1 if l==r: continue r-=1 v=1 if t==2: _,p3,p4=que[p1-1] l,r=p3-1,p4-1 if l==r: continue r-=1 v=-1 yl=l//B yr=r//B for y in [yl,yr]: for i in range(y*B,y*B+B): st1[i]+=lt[y] lt[y]=0 if t==3: a=(X,0) if yl==yr: for i in range(l,r+1): a=op(a,(st1[i],1)) else: for i in range(l,yl*B+B): a=op(a,(st1[i],1)) for i in range(yl+1,yr): a=op(a,st2[i]) for i in range(yr*B,r+1): a=op(a,(st1[i],1)) print(a[1]+1 if a[0]==0 else 0) continue if yl==yr: for i in range(l,r+1): st1[i]+=v st2[yl]=(X,0) for i in range(yl*B,yl*B+B): st2[yl]=op(st2[yl],(st1[i],1)) else: for i in range(l,yl*B+B): st1[i]+=v st2[yl]=(X,0) for i in range(yl*B,yl*B+B): st2[yl]=op(st2[yl],(st1[i],1)) for i in range(yl+1,yr): st2[i]=(st2[i][0]+v,st2[i][1]) lt[i]+=v for i in range(yr*B,r+1): st1[i]+=v for y in [yl,yr]: st2[y]=(X,0) for i in range(y*B,y*B+B): st2[y]=op(st2[y],(st1[i],1))