#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1e5 + 5;
struct Node{
int arr[10], cnt;
}tree[N << 2];
void push_up(Node& node, Node l, Node r)
{
int i = 1, j = 1, k = 1;
while (i <= l.cnt && j <= r.cnt && k <= 8)
{
if (l.arr[i] >= r.arr[j]) node.arr[k++] = l.arr[i++];
else node.arr[k++] = r.arr[j++];
}
while (i <= l.cnt && k <= 8) node.arr[k++] = l.arr[i++];
while (j <= r.cnt && k <= 8) node.arr[k++] = r.arr[j++];
node.cnt = k - 1;
}
void modify(int node, int lef, int rig, int x, int c)
{
if (lef == rig)
{
tree[node].arr[1] = c;
tree[node].cnt = 1;
}
else
{
int mid = (lef + rig) >> 1;
int left_node = node << 1;
int right_node = left_node | 1;
if (x <= mid) modify(left_node, lef, mid, x, c);
else modify(right_node, mid+1, rig, x, c);
push_up(tree[node], tree[left_node], tree[right_node]);
}
}
void bulid_tree(int node, int lef, int rig)
{
if (lef == rig)
{
memset(tree[node].arr, 0, sizeof tree[node].arr);
tree[node].cnt = 0;
}
else
{
int mid = (lef + rig) >> 1;
int left_node = node << 1;
int right_node = node << 1 | 1;
bulid_tree(left_node, lef, mid);
bulid_tree(right_node, mid+1, rig);
}
}
Node query(int node, int lef, int rig, int l, int r)
{
if (l <= lef && rig <= r) return tree[node];
int mid = (lef + rig) >> 1;
int left_node = node << 1;
int right_node = left_node | 1;
Node res;
memset(res.arr, 0, sizeof res.arr);
res.cnt = 0;
if (l <= mid) push_up(res, res, query(left_node, lef, mid, l, r));
if (r > mid) push_up(res, res, query(right_node, mid+1, rig, l, r));
return res;
}
int main()
{
int n, m, x, y;
char op[5];
scanf("%d%d", &n, &m);
bulid_tree(1, 1, n); //初始化
while (m--)
{
scanf("%s%d%d", op, &x, &y);
if (op[0] == 'C') modify(1, 1, n, x, y);
else
{
if (y - x + 1 < 8) puts("0");
else
{
Node res = query(1, 1, n, x, y);
// for (int i = 1; i <= res.cnt; ++i) cout << res.arr[i] << " ";
// cout << endl;
printf("%d\n", res.arr[8]);
}
}
}
return 0;
}