{
TASK:bands
LANG:Pascal
}

program bands;

type TLine = record
      x1, x2: Integer;
      Date: LongInt;
      color: Byte;
     end;

var Lines: array[1..100000] of TLine;
    Lines_Count: Integer;
    M, CDate: LongInt;
    N: Integer;

procedure AddLine(const a, b: Integer; const col: Byte);
var NewLine: TLine;
begin
 If (a >= b) then Exit;

 Inc(CDate);
 Inc(Lines_Count);

 NewLine.x1 := a;
 NewLine.x2 := b;
 NewLine.Date := CDate;
 NewLine.color := col;

 Lines[Lines_Count] := NewLine;
end;

procedure DeleteLine(const Id: LongInt);
var iLine: Integer;
begin
 If not(Id = Lines_Count) then begin
  for iLine := Id to Lines_Count - 1 do Lines[iLine] := Lines[iLine + 1];
 end;
 Dec(Lines_Count);
end;

procedure RemoveLine(const a, b: Integer);
var iCheck: LongInt;
begin
 for iCheck := Lines_Count downto 1 do begin
  If (Lines[iCheck].x2 > a) or (Lines[iCheck].x1 < b) then begin
   If (Lines[iCheck].x1 > a) and (Lines[iCheck].x2 < b) then DeleteLine(iCheck);
   Break;
  end;
 end;
end;

function GetColor(const a: Integer): Byte;
var iCheck: LongInt;
    Answer: Byte;
begin
 Answer := 0;

 for iCheck := Lines_Count downto 1 do begin
  If (Lines[iCheck].x1 <= a) and (Lines[iCheck].x2 > a) then begin

   Answer := Lines[iCheck].color;
   Break;

  end;
 end;

 GetColor := Answer;
end;

procedure Start;
var iCommand: LongInt;
    CommandID: Byte;
    a, b: Integer;
    c: Byte;
begin
 CDate := 0;
 Lines_Count := 0;

 ReadLn(N,M);
 for iCommand := 1 to M do begin

  Read(CommandID);
  case CommandID of

   1:begin
      Read(a); Read(b); Read(c); ReadLn;
      AddLine(a,b,c);
     end;
   2:begin
      Read(a); Read(b); ReadLn;
      RemoveLine(a,b);
     end;
   3:begin
      Read(a); ReadLn;
      WriteLn(GetColor(a));
     end;

  end;

 end;
end;

begin
 Start;
end.
