#include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template using V = vector; template using VV = V>; template using VVV = V>; template using VVVV = VV>; #define rep(i,n) for(ll i=0ll;i void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } // cin.tie(nullptr); // ios::sync_with_stdio(false); // cout << fixed << setprecision(20); void solve(){ ll n,q; cin >> n >> q; V> a; rep(i,n){ ll v; cin >> v; a.eb(v, i); } sort(be(a)); a.eb(INF, INF); V pos(n); ll cnt = 0; rep(i,n){ auto[d,x] = a[i]; pos[x] = cnt; auto[c,xx] = a[i+1]; if(d!=c) cnt++; } rep(i,q){ ll a,b; cin >> a >> b; a--; b--; // cout << pos[b] << " " << pos[a] << endl; cout << max(0ll, -pos[b]+pos[a]-1) << endl; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t=1; // cin >> t; rep(i,t) solve(); }