#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int tree[4 * MAXN];
void build(int node, int start, int end) {
if (start == end) {
tree[node] = 0;
} else {
int mid = (start + end) / 2;
build(node*2, start, mid);
build(node*2+1, mid+1, end);
tree[node] = max(tree[node*2], tree[node*2+1]);
}
}
void update(int node, int start, int end, int i, int k) {
if (start == end) {
tree[node] = k;
} else {
int mid = (start + end) / 2;
if (i <= mid) {
update(node*2, start, mid, i, k);
} else {
update(node*2+1, mid+1, end, i, k);
}
tree[node] = max(tree[node*2], tree[node*2+1]);
}
}
int query(int node, int start, int end, int i, int j) {
if (i > end || j < start) {
return 0;
}
if (i <= start && end <= j) {
return tree[node];
}
int mid = (start + end) / 2;
int p1 = query(node*2, start, mid, i, j);
int p2 = query(node*2+1, mid+1, end, i, j);
return max(p1, p2);
}
int main() {
// freopen("QUERY.INP", "r", stdin);
// freopen("QUERY.OUT", "w", stdout);
int n, m;
cin >> n >> m;
build(1, 1, n);
for (int i = 0; i < m; i++) {
char type;
int a, b;
cin >> type >> a >> b;
if (type == 'S') {
update(1, 1, n, a, b);
} else if (type == 'Q') {
cout << query(1, 1, n, a, b) << "\n";
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYTiA9IDFlNSArIDU7IAppbnQgdHJlZVs0ICogTUFYTl07Cgp2b2lkIGJ1aWxkKGludCBub2RlLCBpbnQgc3RhcnQsIGludCBlbmQpIHsKICAgIGlmIChzdGFydCA9PSBlbmQpIHsKICAgICAgICB0cmVlW25vZGVdID0gMDsKICAgIH0gZWxzZSB7CiAgICAgICAgaW50IG1pZCA9IChzdGFydCArIGVuZCkgLyAyOwogICAgICAgIGJ1aWxkKG5vZGUqMiwgc3RhcnQsIG1pZCk7CiAgICAgICAgYnVpbGQobm9kZSoyKzEsIG1pZCsxLCBlbmQpOwogICAgICAgIHRyZWVbbm9kZV0gPSBt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