/*
TASK:bands
LANG:C++
*/
#include <iostream>
using namespace std;

class Node
{
      public:
             int a,b,c,t;
             Node *left,*right,*mid;
             Node(){a=b=c=0;left=right=mid=0;}
};
class Tree
{
      private:
              Node root;
              int nowTime;
              int nowColor;
      public:
             Tree()
             {
                   root.a=-2;
                   root.b=-1;
                   root.c=0;
             }
             void insert(int x,int y,int z,int T)
             {
                  Node *now=&root;
                  while(now!=0)
                  {
                          if(y<=now->a)
                          {
                                       if(now->left==0)
                                       {
                                                       now->left=new Node;
                                                       now->left->a=x;
                                                       now->left->b=y;
                                                       now->left->c=z;
                                                       now->left->t=T;
                                                       break;
                                       }
                                       now=now->left;
                          }
                          else if(x>=now->b)
                          {
                               
                                       if(now->right==0)
                                       {
                                                       now->right=new Node;
                                                       now->right->a=x;
                                                       now->right->b=y;
                                                       now->right->c=z;
                                                       now->right->t=T;
                                                       break;
                                       }
                                       now=now->right;
                          }
                          else
                          {
                               
                                       if(now->mid==0)
                                       {
                                                       now->mid=new Node;
                                                       now->mid->a=x;
                                                       now->mid->b=y;
                                                       now->mid->c=z;
                                                       now->mid->t=T;
                                                       break;
                                       }
                                       now=now->mid;
                          }
                  }
             }
             void traverse(Node* now,int i)
             {
                 if(now==0) return;
                 if(i>=now->a && i<now->b)
                 {
                              if(now->c!=-1 && now->t>nowTime)
                              {
                                            nowColor=now->c;
                                            nowTime=now->t;
                              }
                 }
                 
                 if(i<now->a)
                 {
                             traverse(now->left,i);
                             traverse(now->mid,i);
                 }
                 else if(i>=now->b)
                 {
                      traverse(now->right,i);
                      traverse(now->mid,i);
                 }
                 else traverse(now->mid,i);
                 
             }
             int search(int i)
             {
                 nowTime=nowColor=0;
                 traverse(&root,i);
                 return nowColor;
             }
             void remove(int x,int y)
             {
                  Node* now=&root,*toDel;
                  int T=-1;
                  while(now!=0)
                  {
                               if(now->a==x && now->b==y && now->t>T && now->c!=-1) {toDel=now;T=now->t;}
                               
                               if(y<=now->a) now=now->left;
                               else if(x>=now->b) now=now->right;
                               else now=now->mid;
                  }
                  if(toDel!=0) toDel->c=-1;
             }
             void prepare(int n)
             {
                  insert(n/2,n/2+1,0,0);
                  insert(n/4,n/4+1,0,0);
                  insert(3*n/4,3*n/4+1,0,0);
                  insert(1*n/8,1*n/8+1,0,0);
                  insert(3*n/8,3*n/8+1,0,0);
                  insert(5*n/8,5*n/8+1,0,0);
                  insert(7*n/8,7*n/8+1,0,0);
            
             }
                  
                               
};
Tree t;
int main()
{
 int cmd,c1,c2,c3,n,m;
    cin>>n>>m;
    t.prepare(n);
    for(int i=1;i<=m;i++)
    {
            cin>>cmd;
            switch(cmd)
            {
                       case 1:
                              cin>>c1>>c2>>c3;
                              t.insert(c1,c2,c3,i);
                              break;
                       case 2:
                              cin>>c1>>c2;
                              t.remove(c1,c2);
                              break;
                       case 3:
                              cin>>c1;
                              cout<<t.search(c1)<<endl;
                              break;
            }
    }

}
