#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<functional>
using namespace std;
typedef unsigned long long ull;
typedef long long LL;
const int maxn = 2e5 + 10;
int n, m, l, r, root, a[maxn];
char s[10];
struct Splays
{
const static int maxn = 2e5 + 10;
const static int INF = 0x7FFFFFFF;
int ch[maxn][2], F[maxn], sz;
int A[maxn], C[maxn], B[maxn];
int Node(int f, int c) { ch[sz][0] = ch[sz][1] = 0; F[sz] = f; A[sz] = C[sz] = c; return sz++; }
void clear(){ sz = 1; ch[0][0] = ch[0][1] = F[0] = 0; C[0] = -INF; }
void rotate(int x, int k)
{
int y = F[x]; ch[y][!k] = ch[x][k]; F[ch[x][k]] = y;
if (F[y]) ch[F[y]][y == ch[F[y]][1]] = x;
F[x] = F[y]; F[y] = x; ch[x][k] = y;
C[x] = C[y]; C[y] = max(A[y], max(C[ch[y][0]], C[ch[y][1]]));
}
void Splay(int x, int r)
{
for (int fa = F[r]; F[x] != fa;)
{
if (F[F[x]] == fa) { rotate(x, x == ch[F[x]][0]); return; }
int y = (x == ch[F[x]][0]), z = (F[x] == ch[F[F[x]]][0]);
y^z ? (rotate(x, y), rotate(x, z)) : (rotate(F[x], z), rotate(x, y));
}
}
void build(int f, int&x, int l, int r)
{
if (l > r) return;
int mid = l + r >> 1;
B[mid] = x = Node(f, a[mid]);
build(x, ch[x][0], l, mid - 1);
build(x, ch[x][1], mid + 1, r);
C[x] = max(A[x], max(C[ch[x][0]], C[ch[x][1]]));
}
void change(int &x, int l, int r)
{
Splay(B[l], x); x = B[l];
A[x] = r;
C[x] = max(r, max(C[ch[x][0]], C[ch[x][1]]));
}
void find(int &x, int l, int r)
{
Splay(B[l - 1], x); x = B[l - 1];
Splay(B[r + 1], ch[x][1]); ch[x][1] = B[r + 1];
printf("%d\n", C[ch[ch[x][1]][0]]);
}
}solve;
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
solve.clear(); a[0] = a[n + 1] = -0x7FFFFFFF; root = 0;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
solve.build(0, root, 0, n + 1);
while (m--)
{
scanf("%s%d%d", s, &l, &r);
if (s[0] == 'Q') solve.find(root, l, r);
else solve.change(root, l, r);
}
}
return 0;
}