#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 200010;
ll readL(){
ll x = 0;
char ch = getchar();
while(!('0'<=ch&&ch<='9')) ch = getchar();
x = ch-'0';
ch = getchar();
while('0'<=ch&&ch<='9'){
x = x*10+ch-'0';
ch = getchar();
}
return x;
}
char readC(){
char ch;
ch = getchar();
while(!('A'<=ch&&ch<='Z')) ch = getchar();
return ch;
}
ll n,m;
ll a[N],res[N],BlockSize,cnt[1000010];
ll ans = 0;
#define bel(x) (x/BlockSize)
struct UPD{
ll idx,val;
} cha[N];
struct QUS{
ll ql,qr,t,id;
bool operator <(const QUS &b) const{
if(bel(ql)!=bel(b.ql)) return bel(ql)<bel(b.ql);
if(bel(qr)!=bel(b.qr)) return bel(qr)<bel(b.qr);
return t<b.t;
}
} Q[N];
void add(ll val){
cnt[val]++;
if(cnt[val]==1) ans++;
}
void del(ll val){
cnt[val]--;
if(cnt[val]==0) ans++;
}
void tchg(ll cpos,ll qid){
if(cha[cpos].idx>=Q[qid].ql&&cha[cpos].idx<=Q[qid].qr){
del(a[cha[cpos].idx]);
add(cha[cpos].val);
}
swap(a[cha[cpos].idx],cha[cpos].val);
}
int main(){
n = readL();m = readL();
BlockSize = sqrt(n);
ll totU = 0,totQ = 0;
for(ll i = 1; i <= n; i++) a[i] = readL();
for(ll i = 1; i <= m; i++){
char op = readC();
if(op=='R'){
totU++;
cha[totU].idx = readL();cha[totU].val = readL();
} else {
totQ++;
Q[totQ] = (QUS){readL(),readL(),totU,totQ};
}
}
sort(Q+1,Q+totQ+1);
for(ll i = 1,l = 1,r = 0,cur = 0; i <= totQ; i++){
while(l<Q[i].ql) del(a[l++]);
while(l>Q[i].ql) add(a[--l]);
while(r<Q[i].qr) add(a[++r]);
while(r>Q[i].qr) del(a[r--]);
while(cur<Q[i].t) tchg(++cur,i);
while(cur>Q[i].t) tchg(cur--,i);
res[Q[i].id] = ans;
}
for(ll i = 1; i <= totQ; i++) printf("%lld\n",res[i]);
return 0;
}