#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q, x, y; cin >> N >> Q; vector A(N), B(N), pos(N); cin >> A; auto comp = [&](int lhs, int rhs){return A[lhs] > A[rhs];}; iota(B.begin(), B.end(), 0); sort(B.begin(), B.end(), comp); while(Q--){ cin >> x >> y; int ans = 0; ans += lower_bound(B.begin(), B.end(), y - 1,comp) - B.begin(); ans -= upper_bound(B.begin(), B.end(), x - 1,comp) - B.begin(); cout << max(0, ans) << '\n'; } }