#include using namespace std; typedef long long ll; void solve() { ll n,q; cin >> n >> q; vector A(n); for (ll i = 0; i < n; ++i) cin >> A[i]; map juni; for (ll i = 0; i < n; ++i) { juni[i]=A[i]; } sort(A.begin(), A.end()); for (ll qqq = 0; qqq < q; ++qqq) { ll kyo = 0; ll x,y; cin >> x >> y; --x, --y; ll xi = lower_bound(A.begin(), A.end(),juni[x]) - A.begin(); ll yi = lower_bound(A.begin(), A.end(),juni[y]) - A.begin(); cout << max((ll)0,xi-yi-1) << endl; } } int main() { solve(); return 0; }