/*
线段树
更新节点,区间最值
*/
#include <stdio.h>
#include <stdlib.h>
const int MAXN = 200001;
int MAX(int x, int y){
return x > y ? x : y;
}
struct segTree{
int L,R;
int max;
};
segTree tree[MAXN << 2];
int st[MAXN];
void bulid(int left,int right, int t){
tree[t].L = left;
tree[t].R = right;
if( left == right )
tree[t].max = st[left];
else {
int mid = ( left + right ) >> 1;
bulid(left, mid, 2 * t);
bulid(mid + 1, right, 2 * t + 1);
tree[t].max = MAX(tree[2 * t].max, tree[2 * t + 1].max);
}
}
void updata(int num, int score, int t){
if(tree[t].L == num && tree[t].R == num){
tree[t].max = score;
} else if(tree[t].L < tree[t].R ){
int mid = (tree[t].L + tree[t].R) >> 1;
if(num > mid){
updata(num, score, 2 * t + 1);
}
if(num <= mid){
updata(num, score, 2 * t);
}
tree[t].max = MAX(tree[2 * t].max, tree[2 * t + 1].max);
}
}
int query(int left, int right, int t){
if (left == tree[t].L && right == tree[t].R ){
return tree[t].max;
} else if(tree[t].L < tree[t].R ){
int mid = (tree[t].L + tree[t].R ) >> 1;
if ( right <= mid ){
return query(left, right, t * 2);
} else if ( left > mid ){
return query(left, right, t * 2 + 1);
} else {
return MAX(query(left, mid, t * 2), query(mid + 1, right, t * 2 + 1));
}
}
return 0;
}
int main(){
// freopen("1012.txt","r",stdin);
int n, m, a, b;
char C;
while (scanf("%d%d",&n, &m) != EOF){
for(int i = 1; i <= n; i++)
scanf("%d",&st[i]);
bulid(1,n,1);
getchar(); //这里错
while(m--){
scanf("%c",&C);
if(C=='Q'){
scanf("%d%d",&a,&b);
printf("%d\n",query(a,b,1));
} else {
scanf("%d%d",&a,&b);
updata(a,b,1);
}
getchar();
}
}
return 0;
}