#include using namespace std; using ll=long long; using ld=long double; template using graph=vector>; template using min_priority_queue=priority_queue,greater>; constexpr int INF32=INT_MAX/2; constexpr ll INF64=1LL<<60; constexpr array DX4={0,1,0,-1}; constexpr array DY4={-1,0,1,0}; constexpr array DX8={0,1,1,1,0,-1,-1,-1}; constexpr array DY8={-1,-1,0,1,1,1,0,-1}; inline int popcnt(ll n){return __builtin_popcountll(n);} template inline bool chmax(T& a,const T& b){return a inline bool chmin(T& a,const T& b){return b=(ll)(n);i--) void _main(); int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout<> class Compress{ private: vector v; public: Compress(){} void push(const T x){ v.push_back(x); } void build(){ sort(v.begin(), v.end(), C()); v.erase(unique(v.begin(),v.end()),v.end()); } size_t size() const { return v.size(); } T nth(const int i) const { assert(0<=i && i> N >> Q; vector A(N); rep(i,0,N) cin >> A[i]; Compress comp; rep(i,0,N) comp.push(A[i]); comp.build(); while(Q--){ ll x, y; cin >> x >> y; x--; y--; int ans = max(0, comp.get(A[x])-comp.get(A[y])-1); cout << ans << endl; } }