#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<cstring>
#include<set>
#include<iterator>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<iomanip>
//#include<unordered_set>
using namespace std;
#define lowbit(x) x&(-x)
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e4 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int block_size;
struct Query
{
int l, r, id, k;
Query(int l = 0, int r = 0, int id = 0, int k = 0) :l(l), r(r), id(id), k(k) {}
bool operator < (const Query &a)const
{
if ((l - 1) / block_size != (a.l - 1) / block_size)
{
return (l - 1) / block_size < (a.l - 1) / block_size;
}
if ((r - 1) / block_size != (a.r - 1) / block_size)
{
return (r - 1) / block_size < (a.r - 1) / block_size;
}
return k < a.k;
}
}q[N];
struct Operation
{
int pos, bef, aft;
Operation(int pos = 0, int bef = 0, int aft = 0) :pos(pos), bef(bef), aft(aft) {}
}op[N];
int a[N], now[N];
int cnt[100 * N];
int l = 1, r = 0, k = 0, ans = 0;
void update(int color, int val)
{
cnt[color] += val;
if (val > 0 && cnt[color] == 1)
{
ans += 1;
}
if (val < 0 && cnt[color] == 0)
{
ans -= 1;
}
}
void update_op(int pos, int color)
{
if (pos >= l && pos <= r)
{
update(color, 1);
update(a[pos], -1);
}
a[pos] = color;
}
int Ans[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
block_size = pow(n, 2.0 / 3);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
now[i] = a[i];
}
int cntq = 0,cntk = 0;
char c;
int x, y;
for (int i = 1; i <= m; i++)
{
cin >> c >> x >> y;
if (c == 'Q')
{
q[++cntq] = Query(x, y, cntq, cntk);
}
else
{
op[++cntk] = Operation(x, now[x], y);
now[x] = y;
}
}
sort(q + 1, q + 1 + cntq);
for (int i = 1; i <= cntq; i++)
{
while (k < q[i].k)
{
k++;
update_op(op[k].pos, op[k].aft);
}
while(k>q[i].k)
{
update_op(op[k].pos, op[k].bef);
k--;
}
while (q[i].l < l)
{
l--;
update(a[l], 1);
}
while (q[i].l > l)
{
update(a[l], -1);
l++;
}
while (q[i].r > r)
{
r++;
update(a[r], 1);
}
while (q[i].r < r)
{
update(a[r], -1);
r--;
}
Ans[q[i].id] = ans;
}
for (int i = 1; i <= cntq; i++)
{
printf("%d\n", Ans[i]);
}
return 0;
}