#include<iostream>
#include<stdio.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 222222
int sum[maxn<<2];
int max(int a, int b)
{
return a > b ? a : b;
}
void Pushup(int rt)
{
sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]);
}
void build(int l, int r, int rt)
{
if (l == r)
{
scanf("%d", &sum[rt]);
return ;
}
int m = (l + r) >> 1;
build(lson);
build(rson);
Pushup(rt);
}
void Update(int a, int b, int l, int r, int rt)
{
if (l == r)
{
sum[rt] = b;
return;
}
int m = (l + r) >> 1;
if (a <= m)
Update(a, b, lson);
else
Update(a, b, rson);
Pushup(rt);
}
int query(int L, int R, int l, int r, int rt)
{
if (L<=l&&r<=R)
{
return sum[rt];
}
int ret = 0;
int m = (l + r) >> 1;
if (L <= m)
ret=max(ret,query(L, R, lson));
if (R > m)
ret=max(ret,query(L, R, rson));
return ret;
}
int main()
{
int n, m;
while (scanf("%d%d", &n, &m) != EOF)
{
build(1, n, 1);
while (m--)
{
char c[2];
int a, b;
scanf("%s%d%d",c, &a, &b);
if (c[0] == ‘Q‘)
printf("%d\n", query(a, b, 1, n, 1));
else Update(a, b, 1, n, 1);
}
}
return 0;
}