#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector A(N+1); for (int i=1; i <= N; ++i) cin >> A[i]; vector B = A; B.erase(B.begin()); sort(B.begin(), B.end()); while (Q--) { int x, y; cin >> x >> y; auto const t = lower_bound(B.begin(), B.end(), A[x]) - upper_bound(B.begin(), B.end(), A[y]); cout << max(t, 0) << '\n'; } }