#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define C(x) ((x) = getchar())
#define L(x) ((x) << 1)
#define R(x) ((x) << 1 | 1)
#define avg(x, y) (((x) + (y)) >> 1)
typedef long long i64;
inline void read(int &x)
{
    /*int ch = x = 0, sign = 1;
    while (!isdigit(C(ch)))
        if (ch == '-') sign = -1;
    for (; isdigit(ch); C(ch))
        x = x * 10 + ch - '0';
    x *= sign;*/
    scanf("%d", &x);
}
const int N = 400500;
int a[N], arr[N << 2];
void build(int k, int l, int r)
{
    if (l == r - 1) return void(arr[k] = a[l]);
    int m = avg(l, r);
    build(L(k), l, m);
    build(R(k), m, r);
    arr[k] = max(arr[L(k)], arr[R(k)]);
}
void modify(int k, int l, int r, int x, int y, int v)
{
    if (x <= l && r <= y)
        return void(arr[k] = v);
    int m = avg(l, r);
    if (x < m) modify(L(k), l, m, x, y, v);
    if (y > m) modify(R(k), m, r, x, y, v);
    arr[k] = max(arr[L(k)], arr[R(k)]);
}
int query(int k, int l, int r, int x, int y)
{
    if (x <= l && r <= y)
        return arr[k];
    int m = avg(l, r);
    int res = 0;
    if (x < m) res = max(res, query(L(k), l, m, x, y));
    if (y > m) res = max(res, query(R(k), m, r, x, y));
    return res;
}
int main()
{
    int n, m;
    while (~scanf("%d%d", &n, &m))
    {
        memset(a, 0, sizeof a);
        memset(arr, 0, sizeof arr);
        for (int i = 0; i < n; i++) read(a[i]);
        build(1, 0, n);
        while (m--)
        {
            int op = 0, x, y, z;
            while (op != 'U' && op != 'Q') C(op);
            if (op == 'Q')
            {
                read(x), read(y);
                printf("%d\n", query(1, 0, n, x - 1, y));
            }
            else
            {
                read(x), read(z);
                modify(1, 0, n, x - 1, x, z);
            }
        }
    }
    return 0;
}