/*
TASK:bands
LANG:C++
*/
#include<stdio.h>
#include<algorithm>
#include<vector>
#define ADD 1
#define REMOVE 2
#define CHECK 3
using namespace std;
int c1,x,z,y,a,type,b,c,i,j;
int n,m,color[100000],end[100000];
vector<pair<int,int> > v;
bool used[100000];
pair<int,int> tmp;

/*powered by battlefrenzy*/
int binsearch(int i)
{
int grr=0,x=1;
while(x<c1)
           x<<=1;

for(x;x>0;x>>=1)
if(v[(grr+x)].first<=i&&grr+x<c1)
                                  grr+=x;
return grr;
}



void input()
{
scanf("%d%d",&n,&m);
//v.heap_push(n+1,1);
tmp.first=0;
tmp.second=0;
v.push_back(tmp);
tmp.first=n+1;
tmp.second=n+2;
v.push_back(tmp);
end[0]=n;
end[1]=n+2;
color[0]=0;
color[1]=0;
c1=2;
used[0]=1;
used[1]=1;
return;
}

int main()
{
input();

for(z=0;z<m;z++)
{
scanf("%d",&type);
if(type==ADD)
             {
             scanf("%d%d%d",&a,&b,&c);
             tmp.first=a;
             tmp.second=c1;
             v.push_back(tmp);
             end[c1]=b;
             used[c1]=1;
             color[c1++]=c;
             }
if(type==REMOVE)
                {
                scanf("%d%d",&i,&j);
                sort(v.begin(),v.end());
                x=binsearch(i);
                while(end[x]!=j)x--;
                used[x]=0;
                }

if(type==CHECK)
               {
               scanf("%d",&i);
               sort(v.begin(),v.end());
               x=binsearch(i+1);
               while(end[v[x].second]<i||!used[x])x--;
               printf("%d\n",color[v[x].second]);
               }
}
return 0;
}


               
