#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long ll;
class segtree {
public:
segtree(vector<ll>& a) : n(a.size()), st(4*n, vector<ll>()) { build(a, 0, 0, n); }
ll query(ll l, ll r, ll lim) { return query(0, 0, n, l, r, lim); } // In range [l,r) counts how many items are greater or equal than lim
private:
ll n;
vector<vector<ll>> st;
void build(vector<ll> a, ll idx, ll l, ll r) {
if (l == r-1) { st[idx].push_back(a[l]); return; }
ll m = (l+r)/2;
build(a, L(idx), l, m);
build(a, R(idx), m, r);
merge(st[L(idx)].begin(), st[L(idx)].end(), st[R(idx)].begin(), st[R(idx)].end(), back_inserter(st[idx]));
}
ll query(ll idx, ll l, ll r, ll ql, ll qr, ll lim) {
if (ql <= l && r <= qr) { return st[idx].end() - lower_bound(st[idx].begin(), st[idx].end(), lim); }
if (r <= ql || qr <= l) return 0;
ll m = (l+r)/2;
ll lv = query(L(idx), l, m, ql, qr, lim);
ll rv = query(R(idx), m, r, ql, qr, lim);
return lv + rv;
}
ll L(ll idx) { return idx*2+1; }
ll R(ll idx) { return idx*2+2; }
};
int main() {
ll n, q; cin >> n >> q;
vector<ll> x(n, 0), y(n, 0);
for (int i = 0; i < n; i++) cin >> x[i];
unordered_map<ll, ll> prevIdx;
for (int i = n-1; i >= 0; i--) {
if (prevIdx.count(x[i]) == 0) y[i] = n;
else y[i] = prevIdx[x[i]];
prevIdx[x[i]] = i;
}
segtree st(y);
for (int i = 0; i < q; i++) {
ll a, b; cin >> a >> b;
a--, b--;
ll res = st.query(a, b+1, b+1);
cout << res << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CgpjbGFzcyBzZWd0cmVlIHsKcHVibGljOgoJc2VndHJlZSh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