#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
const int maxn = 2e5 + 5;
int n, q, x, y, A[maxn], B[maxn];
vector<int> segtree[4 * maxn];
map<int, int> seen;
void build(int r, int s, int e) {
if(s != e) {
int mid = (s + e) / 2;
build(r * 2, s, mid);
build(r * 2 + 1, mid + 1, e);
segtree[r].resize(e - s + 1);
merge(segtree[r * 2].begin(), segtree[r * 2].end(), segtree[r * 2 + 1].begin(), segtree[r * 2 + 1].end(), segtree[r].begin());
} else {
segtree[r].push_back(B[s]);
}
}
int qr(int r, int s, int e, int i, int j) {
if(e < i || s > j) return 0;
if(i <= s && j >= e) {
return segtree[r].end() - upper_bound(segtree[r].begin(), segtree[r].end(), j);
}
int mid = (s + e) / 2;
return qr(r * 2, s, mid, i, j) + qr(r * 2 + 1, mid + 1, e, i, j);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> A[i];
}
for(int i = n; i > 0; i--) {
if(seen.count(A[i]) != 0) B[i] = seen[A[i]];
else B[i] = n + 1;
seen[A[i]] = i;
}
build(1, 1, n);
for(int i = 0; i < q; i++) {
cin >> x >> y;
cout << qr(1, 1, n, x, y) << '\n';
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTxjbWF0aD4KI2luY2x1ZGU8bWFwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBtYXhuID0gMmU1ICsgNTsKaW50IG4sIHEsIHgsIHksIEFbbWF4bl0sIEJbbWF4bl07CnZlY3RvcjxpbnQ+IHNlZ3RyZWVbNCAqIG1heG5dOwptYXA8aW50LCBpbnQ+IHNlZW47Cgp2b2lkIGJ1aWxkKGludCByLCBpbnQgcywgaW50IGUpIHsKCWlmKHMgIT0gZSkgewoJCWludCBtaWQgPSAocyArIGUpIC8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