#include<bits/stdc++.h>
using namespace std;
int FindMax(vector<int>& vec,int A,int B)
{
int MaxValue=vec[A-1];
for(int i=A;i<B;i++)
{
if(vec[i]>MaxValue)
{
MaxValue=vec[i];
}
}
return MaxValue;
}
int main()
{
ios::sync_with_stdio(false);
int N,M;
int tmp;
int MaxValue;
int A,B;
char op;
vector<int> vec;
while(cin>>N>>M)
{
vec.clear();
for(int i=0;i<N;i++)
{
cin>>tmp;
vec.push_back(tmp);
}
while(M--)
{
cin>>op;
//cout<<op<<endl;
cin>>A>>B;
if(op=='Q')
{
if(B<A)
{
swap(A,B);
}
MaxValue=FindMax(vec,A,B);
cout<<MaxValue<<endl;
}
else
{
vec[A-1]=B;
// cout<<A<<":"<<B<<endl;
}
}
}
return 0;
}