#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int tr[200005];
int a[200005];
void build(int root, int a[], int l, int r)
{
    if (l == r)
        tr[root] = a[l];
    else
    {
        int mid = (l + r) / 2;
        build(root * 2 + 1, a, l, mid);
        build(root * 2 + 2, a, mid + 1, r);
        tr[root] = max(tr[root * 2 + 1], tr[root * 2 + 2]);
    }
    return;
}
int q(int root, int ql, int qr, int l, int r)
{
    //cout << "#" << ql + 1 << " " << qr + 1 << endl;
    if (ql < r || qr > l) return printf("# query %d %d ret %d\n", l + 1, r + 1, -1), -1;
    if (ql <= l && r <= qr) return printf("# query %d %d ret %d\n", l + 1, r + 1, tr[root]), tr[root];
    int mid = (l + r) / 2;
    int ans = 0;
	max(q(root * 2 + 1, ql, qr, l, mid), q(root * 2 + 2, ql, qr, mid + 1, r));
    printf("# query %d %d ret %d\n", l + 1, r + 1, ans);
    return ans;
}
void mof(int root, int l, int r, int now, int nw)
{
    if (l == r)
    {
        if (now == l) tr[root] = nw;
        //printf("# modify %d %d to %d \n", l+1, r+1, tr[root]);
        return;
    }
    int mid = (l + r) / 2;
    if (now <= mid)
        mof(root * 2 + 1, l, mid, now, nw);
    else
        mof(root * 2 + 2, mid + 1, r, now, nw);
    tr[root] = max(tr[root * 2 + 1], tr[root * 2 + 2]);
    //printf("# modify %d %d to %d \n", l+1, r+1, tr[root]);
    return;
}
int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        for (int i = 0; i < n; i++) cin >> a[i];
        build(0, a, 0, n - 1);
        char h;
        int a, b;
        for (int i = 0; i < m; i++)
        {
            cin >> h;
            cin >> a >> b;
            if (h == 'Q')
                cout << q(0, a - 1, b - 1, 0, n - 1) << endl;
            else
                mof(0, 0, n - 1, a - 1, b);
        }
    }
    system("pause");
    return 0;
}