#include<bits/stdc++.h>
using namespace std;
#define icc ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
#define PII pair<int,int>
const int N=1e6+5, INF=1e9+5, mod=1e9+7;
int tree[N];
int n,m;
int a[N];
int lowbit(int x)
{
return x&(-x);
}
void updata(int x,int val)
{
while(x<=n)
{
tree[x]=val;
for(int i=1;i<lowbit(x);i<<=1)
{
tree[x]=max(tree[x],tree[x-i]);
}
x+=lowbit(x);
}
}
int query(int l,int r)
{
int ans=0;
while(l<=r)
{
ans=max(ans,a[r]);
r--;
while(r-l>=lowbit(r))
{
ans=max(ans,tree[r]);
r-=lowbit(r);
}
} return ans;
}
signed main()
{
icc
while(cin>>n>>m)
{
for(int i=1;i<=n;i++) tree[i]=0;
for(int i=1;i<=n;i++)
cin>>a[i], updata(i,a[i]);
while(m--)
{
char ch;
int x,y;
cin>>ch>>x>>y;
if(ch=='U')
{
if(a[x]<y) updata(x,y),a[x]=y;
}
else
cout<<query(x,y)<<endl;
}
}
}