/*
Coded By : MiYu
Link : http://www.cnblogs.com/MiYu || http://www.cppblog.com/MiYu
Author By : MiYu
Test : 1
Program : 1754
*/
//#pragma warning( disable:4789 )
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
inline int max ( int a, int b ){
return a > b ? a : b;
}
typedef struct seg_Tree {
int left, right;
int mid() { return (left+right)>>1; }
int max;
}S;
S seg[605000];
int key[200010];
int creat ( int left, int right, int root = 1 ){
seg[root].left = left;
seg[root].right = right;
if ( left == right )
return seg[root].max = key[left];
int mid = seg[root].mid();
return seg[root].max = max ( creat ( left, mid, root << 1 ),creat ( mid + 1, right, ( root << 1 ) + 1 ) );
}
void modify ( int val, int pos, int r = 1 ){
if ( seg[r].left == seg[r].right ){
seg[r].max = val;
return;
}
int mid = seg[r].mid();
if ( pos <= mid ){
modify ( val, pos, r << 1 );
} else {
modify ( val, pos, ( r << 1 ) + 1 );
}
seg[r].max = max ( seg[r<<1].max, seg[ (r<<1) + 1 ].max );
}
int quy ( int left, int right, int r = 1 ){
if ( seg[r].left == left && seg[r].right == right ){
return seg[r].max;
}
int mid = seg[r].mid();
if ( right <= mid ){
return quy ( left, right, r << 1 );
} else if ( left > mid ) {
return quy ( left, right, (r << 1) + 1 );
} else {
return max ( quy ( left, mid, r << 1 ), quy ( mid + 1, right, (r << 1) + 1 ) );
}
}
inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
int main ()
{
int N, M, x, y;
while ( scan_d(N) && scan_d(M) ){
for ( int i = 1; i <= N; ++ i ){
scan_d( key[i] );
}
creat ( 1, N );
while ( M -- ){
char ask[5];
scanf ( "%s", ask );
scan_d(x);
scan_d(y);
switch ( ask[0] ){
case 'Q': printf ( "%d\n", quy ( x,y ) );
break;
case 'U': modify ( y, x );
}
}
}
return 0;
}
/*
5 6
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
*/