#include using ll=long long; const long long INF=1LL<<60; void Compress(std::vector& A) { std::vector B=A;// std::sort(B.begin(),B.end()); B.erase(std::unique(B.begin(),B.end()),B.end()); for(auto& a:A){ a=static_cast(std::lower_bound(B.begin(),B.end(),a)-B.begin()); } } int main(){ ll n,q; std::cin >> n >> q; std::vectorA(n); for(auto&a:A){ std::cin >> a; a*=-1; } Compress(A); while(q--){ ll x,y; std::cin >> x >> y; --x;--y; std::cout << std::max(0LL,A[y]-A[x]-1) << '\n'; } }