#include <iostream>
using namespace std;
int n,m;
struct tree
{
int l,r,key;
}node[600000];
int score[600000];
int X,Y;
int max(int x,int y)
{
if(x>y)return x;
else
return y;
}
int createtree(int a,int b,int i)
{
int mid=(a+b)/2;
node[i].l=a;
node[i].r=b;
if(a==b)
{
node[i].key=score[a];
return node[i].key;
}
else
{
node[i].key=max(createtree(a,mid,2*i),createtree(mid+1,b,2*i+1));
return node[i].key;
}
}
void update(int i,int a,int key)
{
node[i].key=max(node[i].key,key);
int mid=(node[i].l+node[i].r)/2;
if(node[i].l==node[i].r)
return ;
if(a>mid)
update(2*i+1,a,key);
else
update(2*i,a,key);
}
int Quetion(int i,int a,int b)
{
if(node[i].l==a&&node[i].r==b)
return node[i].key;
else
{
int mid=(node[i].l+node[i].r)/2;
if(a<=mid&&b>=mid+1)
{
return max(Quetion(2*i,a,mid),Quetion(2*i+1,mid+1,b));
}
else
if(b>=mid+1)
{
return Quetion(2*i+1,a,b);
}
else
{
return Quetion(2*i,a,b);
}
}
}
int main()
{
char ch;
int a,b;
while(scanf("%d %d",&n,&m)!=EOF)
{
int i;
for(i=1;i<=n;i++)
scanf("%d",&score[i]);
createtree(1,n,1);
while(m--)
{
getchar();
scanf("%c %d %d",&ch,&a,&b);
if(ch=='U')
update(1,a,b);
else
printf("%d\n",Quetion(1,a,b));
}
}
return 0;
}