package shaohv.Io;
import java.util.Scanner;
import java.util.ArrayList;
/*
5 7
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 4 5
U 2 9
Q 1 5
*
*/
public class ScannerExample {
public static void main(String[] args)throws Exception{
Scanner s = new Scanner(System.in);
int[] data = new int[2];
do{
data[0] = s.nextInt();
data[1] = s.nextInt();
ArrayList<Integer> array = new ArrayList<Integer>();
for(int i = 0; i < data[0]; i ++){
array.add(s.nextInt());
}
int num = 0;
char a ;
int b,c;
while(num < data[1]){
a = s.next().charAt(0);
b = s.nextInt();
c = s.nextInt();
if('Q' == a){
int start, end;
if(b <= c){
start = b - 1;
end = c - 1;
}else{
start = c - 1;
end = b - 1;
}
int max = array.get(start);
for(int index = start; index <= end; index ++){
if(array.get(index) >= max)
max = array.get(index);
}
//result.add(max);
System.out.println(max);
}
if('U' == a){
int index1 = b - 1;
int newValue = c;
array.set(index1, newValue);
}
s.nextLine(); //因为nextInt不换行,所以要读取每行后面的最后一个换行符
num ++;
}
}while(s.hasNext());
s.close();
}
}