#include #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(x) x.begin(), x.end() using namespace std; using ll=long long; using ld=long double; using P=pair; #include using namespace atcoder; //using mint=static_modint<998244353>; using mint=static_modint<1000000007>; ll n,q; vector a; int main(){ cin>>n>>q; a.resize(n); rep(i,n)cin>>a[i]; vector b(n); rep(i,n)b[i]=a[i]; sort(all(b)); rep(i,q){ int x,y;cin>>x>>y; x--;y--; auto it1=upper_bound(all(b),a[y]); auto it2=lower_bound(all(b),a[x]); int idx1=it1-b.begin(); int idx2=it2-b.begin(); cout<