#include using namespace std; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = n; i > 0; --i) #define bitrep(i, n) for (ll i = 0; i < (1 << n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define yesNo(b) ((b) ? "Yes" : "No") using ll = long long; using ull = unsigned long long; using ld = long double; string alphabet = "abcdefghijklmnopqrstuvwxyz"; string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const double pi = 3.141592653589793; ll smallMOD = 998244353; ll bigMOD = 1000000007; int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int main() { ll n, q; cin >> n >> q; vector> a(n); rep(i, n) { ll x; cin >> x; a[i] = {x, i + 1}; } sort(all(a)); reverse(all(a)); vector X(n), Y(n); rep(i, n) { X[i] = a[i].second; } rep(i, n) { Y[X[i] - 1] = i + 1; } rep(i, q) { ll x, y; cin >> x >> y; cout << max(0ll, Y[y - 1] - Y[x - 1] - 1) << endl; } return 0; }