# bzoj 2120 数颜色 (树状数组套主席树)

#include <bits/stdc++.h>
using namespace std;

#define N 30030
#define M 1000030
#define LL long long
#define md ((ll + rr) >> 1)

int n, q, a[N];

struct ope {
int t, x, y;
}p[N];
int san[N], scnt;
int ch[N * 20 * 20][2], cnt[N * 20 * 20], tot;

int rt[N];
set<int> st[N];
set<int>::iterator it, it2;

int pre[N], vis[N];
int haxi(int x) {
return lower_bound(san + 1, san + scnt + 1, x) - san;
}
int update(int i, int x, int v, int ll, int rr) {
int k = ++tot;
ch[k][0] = ch[i][0];
ch[k][1] = ch[i][1];
cnt[k] = cnt[i] + v;
if(ll == rr) return k;
if(x <= md) ch[k][0] = update(ch[i][0], x, v, ll, md);
else ch[k][1] = update(ch[i][1], x, v, md + 1, rr);
return k;
}
int query(int i, int l, int r, int ll, int rr) {
if(ll == l && rr == r) return cnt[i];
if(r <= md) return query(ch[i][0], l, r, ll, md);
if(l > md) return query(ch[i][1], l, r, md + 1, rr);
return query(ch[i][0], l, md, ll, md) + query(ch[i][1], md + 1, r, md + 1, rr);
}

void mdf(int x, int p, int v) {
while(x <= n) {
rt[x] = update(rt[x], p, v, 0, n);
x += x & -x;
}
}
int qry(int x, int p) {
int ret = 0;
while(x) {
ret += query(rt[x], 0, p, 0, n);
x -= x & -x;
}
return ret;
}
int main() {

scanf("%d%d", &n, &q);

for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
san[++scnt] = a[i];
}
for(int i = 1; i <= q; ++i) {
char op[3];
scanf("%s%d%d", op, &p[i].x, &p[i].y);
if(op[0] == 'Q') p[i].t = 1;
else p[i].t = 0;
if(p[i].t == 0) san[++scnt] = p[i].y;
}
sort(san + 1, san + scnt + 1);
scnt = unique(san + 1, san + scnt + 1) - san - 1;
for(int i = 1; i <= n; ++i) a[i] = haxi(a[i]);
for(int i = 1; i <= q; ++i) {
if(p[i].t == 0) p[i].y = haxi(p[i].y);
}
for(int i = 1; i <= scnt; ++i) st[i].insert(0);
for(int i = 1; i <= n; ++i) {
st[a[i]].insert(i);
pre[i] = vis[a[i]];
vis[a[i]] = i;
}
for(int i = 1; i <= scnt; ++i) st[i].insert(n + 1);
for(int i = 1; i <= n; ++i) {
mdf(i, pre[i], 1);
}
for(int i = 1; i <= q; ++i) {
int x = p[i].x, y = p[i].y;
if(p[i].t == 0) {
if(a[x] == y) continue;
it = st[a[x]].lower_bound(x);
++it;
if((*it) != n + 1) {
mdf(*it, pre[*it], -1);
pre[*it] = pre[x];
mdf(*it, pre[x], 1);
}
st[a[x]].erase(x);
it = st[y].lower_bound(x);
int v = pre[*it];
if((*it) != n + 1) {
mdf(*it, pre[*it], -1);
pre[*it] = x;
mdf(*it, x, 1);
}
else {
--it;
v = *it;
}

mdf(x, pre[x], -1);
pre[x] = v;
mdf(x, pre[x], 1);
st[y].insert(x);
a[x] = y;
}
else {
int ans = qry(y, x - 1) - qry(x - 1, x - 1);
printf("%d\n", ans);
}
}
return 0;
}