#include<bits/stdc++.h>
using namespace std;
int a,b,c,d[800005],e,f,g,h;
char ch;
void update(int x,int y,int z,int aa,int bb){
if(x==y) {
d[z]=aa;
return;
}
int m=(x+y)/2;
if(bb<=m) update(x,m,z*2,aa,bb);
else update(m+1,y,z*2+1,aa,bb);
d[z]=min(d[z*2],d[z*2+1]);
}
// bb ag
int queer(int x,int y,int z,int aa,int bb){
int m=(x+y)/2;
if(y<bb or d[z]>aa) return 0;
if(x==y) return x;
if(x>=bb) {
if(d[z*2]<=aa) return queer(x,m,z*2,aa,bb);
else return queer(m+1,y,z*2+1,aa,bb);
}
else{
if(bb>m) return queer(m+1,y,z*2+1,aa,bb);
else{
int tem=queer(x,m,z*2,aa,bb);
if(tem==0 or tem==1e9+7) return queer(m+1,y,z*2+1,aa,bb);
else return tem;
}
}
}
int main(){
cin>>a>>b;
for(int i=0;i<=4*a;i++){
d[i]=1e9+7;
}
for(int i=0;i<b;i++){
cin>>ch>>e>>f;
if(ch=='M'){
update(1,a,1,e,f);
}
else{
int tep=queer(1,a,1,e,f);
if(tep!=0 and tep!=1e9+7)cout<<tep<<endl;
else cout<<"-1\n";
}
}
}