{
TASK: bands
LANG: Pascal
}
Program Bands;
 Var Color: Array[0..20005, 0..5000] of Byte;
     BrBand: Array[0..5000] of Integer;
     Res: Array[1..100005] of Byte;
     Nach, Kray : Array[1..20005] of Integer;
     N, M, O, E, I, J, C, Br, Br1, S, T: Longint;
     Bl, Bl1: Boolean;
 Begin
  ReadLn(N, M);
  For O := 1 to M do
   Begin
    Read(E);
    Case E of
    1: Begin
        Read(I, J, C);
        Inc(Br);
        Nach[Br] := I;
        Kray[Br] := J;
        For S := I to J - 1 do Begin
                                Inc(BrBand[S]);
                                Color[S][BrBand[S]] := C;
                               End;
       End;
    2: Begin
        Bl := False;
        Read(I, J);
        {For S := I to J - 1 do Begin
                                Color[S][BrBand[S]] := 0;
                                Dec(BrBand[S]);
                               End;}
        For S := Br downto 1 do
         If (Nach[S] >= I) and (Kray[S] <= J) then Begin Bl := True; Break End;
        If Bl then
        For T := Br downto S + 1 do
         Begin
          Bl1 := False;
          If (Nach[T] >= Nach[S]) and (Nach[T] < Kray[S]) then Bl1 := True;
          If (Kray[T] > Nach[S]) and (Kray[T] >= Kray[S]) then Bl1 := True;
          If Bl1 then Break;
         End;
        If not(Bl1) then
         For T := Nach[S] to Kray[S] - 1 do Begin
                                             Color[T][BrBand[T]] := 0;
                                             Dec(BrBand[T]);
                                            End;
       End;
    3: Begin
        Read(I);
        Inc(Br1);
        Res[Br1] := Color[I][BrBand[I]];
       End;
    End;
   End;
  For I := 1 to Br1 do WriteLn(Res[I]);
 End.
