#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const ll N=1e5+5,INF=1e9;
ll a[N],l,r,x,y,z,ans,n,mx,mn,k,q;
bool ok,okk;
ll t[4*N];
void update(int v, int tl, int tr, int pos, int x) {
if (tl==tr) { t[v]=x; return ; }
int tm=(tl+tr)/2;
if (pos<=tm)
update(v*2, tl, tm, pos, x);
else
update(v*2+1, tm+1, tr, pos, x);
t[v]=min(t[v*2], t[v*2+1]);
}
int query(int v,int tl,int tr,int pos,int x){
if (tr<pos || t[v]>x) return -1;
if (tl==tr) return tl;
int tm=(tl+tr)/2;
int ans=query(v*2,tl,tm,pos,x);
if (ans!=-1) return ans;
ans=query(v*2+1,tm+1,tr,pos,x);
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> q;
for (int i=1; i<=4*n; i++) t[i]=INF;
while (q--){
char cc;
cin >> cc;
if (cc=='D'){
cin >> x >> y;
cout<<query(1,1,n,y,x)<<endl;
}
else{
cin >> x >> y;
update(1,1,n,y,x);
}
}
}