#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, w; rep(i,n){ ll v; cin >> v; a.eb(v); w.eb(v); } sort(be(a)); rep(i,q){ ll c,b; cin >> c >> b; c--; b--; ll x = lower_bound(be(a), w[c]) - a.begin(); ll y = upper_bound(be(a), w[b]) - a.begin(); cout << max(0ll, x-y) << endl; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t=1; // cin >> t; rep(i,t) solve(); }