#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAXN 200020
#define MAX(a,b) (a>b?a:b)
#define Lowbit(x) (x & (-x))
int num[MAXN]={0,3,1,2,4,5,8,7,9,6};//注意从下标为1的位置开始保存数据
int C[MAXN];
int Query(int l,int r){
int ans=num[r];
while(true){
ans=MAX(ans,num[r]);
if(r==l) break;
for(r-=1;r-l>=Lowbit(r);r-=Lowbit(r)){
ans=MAX(ans,C[r]);
}
}
return ans;
}
void Modify(int p,int val,int end){
num[p]=val;
for(int i=p;i<=end;i+=Lowbit(i)){
C[i]=val;
for(int j=1;j<Lowbit(i);j<<=1){
C[i]=MAX(C[i],C[i-j]);
}
}
}
int main(int argc, char *argv[])
{
int n,m;
char op[3];
int s,e;
while(scanf("%d%d",&n,&m)!=EOF){
memset(C,0,sizeof(C));
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++){
scanf("%d",&num[i]);
Modify(i,num[i],n);
}
while(m--){
scanf("%s%d%d",op,&s,&e);
if(op[0]=='Q')
printf("%d
",Query(s,e));
else
Modify(s,e,n);
}
}
}