#include using namespace std; using ll = long long; using ld = long double; #ifdef LOCAL #include #else #define debug(...) void(0) #endif #include using namespace atcoder; using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector A(N); for(int i = 0; i < N; i++) cin >> A[i]; map MP; for(int i = 0; i < N; i++) MP[i + 1] = A[i]; sort(A.begin(), A.end()); while(Q--) { ll x, y; cin >> x >> y; ll l = distance(A.begin(), lower_bound(A.begin(), A.end(), MP[x])); ll r = distance(A.begin(), upper_bound(A.begin(), A.end(), MP[y])); if(l < r) cout << 0 << endl; else cout << l - r << endl; } }