program happya;
var
n,m,i,j,ans:longint;
cha:char;
candy:array[1..100000] of longint;
procedure add;
var
a,b,c:longint;
begin
readln(a,b,c);
for i:=a to b do
candy[i]:=candy[i]+c;
end;
procedure put;
var
a,b,p,max:longint;
begin
max:=-1;
readln(a,b);
for i:=a to b do
if candy[i]>max then
begin
max:=candy[i];
p:=i;
end;
writeln(max);
candy[p]:=0;
end;
begin
assign(input,'happya.in');
assign(output,'happya.out');
reset(input);
rewrite(output);
readln(n,m);
for j:=1 to m do
begin
read(cha);
if cha='I' then add
else put;
end;
close(input);
close(output);
end.