#include using ll=long long; #define rep(i,s,n) for (ll i = (s); i < (n); i++) using namespace std; using Graph = vector>; ll MOD=998244353; const ll INF=1e18; int main(){ ll N,Q; cin>>N>>Q; vector A(N); vector Z(N); rep(i,0,N){ cin>>A[i]; Z[i]=A[i]; } sort(A.begin(),A.end()); rep(i,0,Q){ ll x,y; cin>>x>>y; x--;y--; auto itrX=lower_bound(A.begin(),A.end(),Z[x]); ll idxX=distance(A.begin(),itrX); auto itrY=upper_bound(A.begin(),A.end(),Z[y]); itrY--; ll idxY=distance(A.begin(),itrY); cout<