rt
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ls p<<1
#define rs p<<1|1
const int N=1e6;
int a[N];
struct tree
{
int l,r;
int max;
}t[4*N];
void bulid(int p,int l,int r)
{
t[p].l=l,t[p].r=r;
if(l==r)
{
t[p].max=a[l];
return;
}
int mid=(l+r)>>1;
bulid(ls,l,mid);
bulid(rs,mid+1,r);
t[p].max=max(t[ls].max,t[rs].max);
}
void change(int p,int x,int y)
{
if(x<=t[p].l && y>=t[p].r)
{
t[p].max=y;
return;
}
int mid=(t[p].l+t[p].r)>>1;
if(x<=mid) change(ls,x,y);
else change(rs,x,y);
t[p].max=max(t[ls].max,t[rs].max);
}
int find(int p,int x,int y)
{
if(x<=t[p].l && y>=t[p].r) return t[p].max;
int mid=(t[p].l+t[p].r)>>1;
int ans=-0x3f3f3f;
if(x<=mid) ans=max(ans,find(ls,x,y));
if(y>mid) ans=max(ans,find(rs,x,y));
return ans;
}
signed main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i)
cin>>a[i];
bulid(1,1,n);
for(int i=1;i<=m;++i)
{
string q;
int x,y;
cin>>q>>x>>y;
if(q=="U")
{
if(x<=y)
change(1,x,y);
}
else
cout<<find(1,x,y)<<endl;
}
}