#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define maxn 200005
#define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R
struct TreeNode
{//bestMark保存LR区间最好的成绩
int bestMark, L, R;
int Mid(){return (L+R)/2;}
}tree[maxn*4];
int Mart[maxn];//保存所有学生的成绩
void Build(int root, int L, int R)
{
tree[root].L = L, tree[root].R = R;
if(L == R)
{
tree[root].bestMark = Mart[L];
return ;
}
Build(Lson);
Build(Rson);
tree[root].bestMark = max(tree[root<<1].bestMark, tree[root<<1|1].bestMark);
}
//使k点的成绩变为e
void Insert(int root, int k, int e)
{
tree[root].bestMark = max(tree[root].bestMark, e);
if(tree[root].L == tree[root].R)
return ;
if(k <= tree[root].Mid())
Insert(root<<1, k, e);
else
Insert(root<<1|1, k, e);
}
//查询区间LR最好的成绩
int Query(int root, int L, int R)
{
if(tree[root].L == L && tree[root].R == R)
return tree[root].bestMark;
if(R <= tree[root].Mid())
return Query(root<<1, L, R);
else if(L > tree[root].Mid())
return Query(root<<1|1, L, R);
else
return max(Query(Lson), Query(Rson));
}
int main()
{
int i, N, M;
while(scanf("%d%d", &N, &M) != EOF)
{
for(i=1; i<=N; i++)
scanf("%d", &Mart[i]);
Build(1, 1, N);
int x, y; char s[10];
while(M--)
{
scanf("%s%d%d", s, &x, &y);
if(s[0] == ‘U‘)
Insert(1, x, y);
else
{
int ans = Query(1, x, y);
printf("%d\n", ans);
}
}
}
return 0;
}