#include #include #include using namespace std; using ll = long long; int main(void){ int n, q; cin >> n >> q; vector a(n), b; for(auto&x:a) cin >> x; b=a; sort(begin(b), end(b)); while(q--){ int x, y; cin >> x >> y; x--, y--; if(a[y]>=a[x]){ cout << 0 << '\n'; continue; } int ans=lower_bound(begin(b), end(b), a[x])-upper_bound(begin(b), end(b), a[y]); cout << ans << '\n'; } return 0; }