#include using namespace std; int main() { int N, Q; cin >> N >> Q; vector> A(N); vector B(N); for (int i = 0; i < N; i++) { cin >> A.at(i).first; A.at(i).second = i; } sort(A.rbegin(), A.rend()); for (int i = 0; i < N; i++) B.at(A.at(i).second) = i; for (int i = 0; i < Q; i++) { int x, y; cin >> x >> y; cout << max(0, B.at(y - 1) - B.at(x - 1) - 1) << endl; } }