#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0;i < n;i++) template<class T> bool chmin(T &a,T b){ if(a>b){a = b;return true;} return false; } template<class T> bool chmax(T &a,T b){ if(a<b){a = b;return true;} return false; } using ll = long long; using ld = long double; const int INF = 1e9+5; // const int mod = 1000000007; const int mod = 998244353; void no(){ cout << "No" << endl;exit(0); } void yes(){ cout << "Yes" << endl; exit(0); } #define all(x) x.begin(),x.end() int main(){ int N,Q;cin >> N >> Q; vector<int>A(N); rep(i,N)cin >> A[i];//ゴールまでのキョリ vector<int>vec = A; sort(all(vec)); rep(qi,Q){ int x,y;cin >> x >> y; x--;y--; //xがyに追いつくためには何人ぬかす必要があるか? //等号は含めない // xよりも値が小さい、yよりも大きいのは何人いるか? auto itx = lower_bound(all(vec),A[x]);itx--; auto ity = upper_bound(all(vec),A[y]); cout << max(0,int(itx-ity+1)) << endl; } }