#include int main() { using namespace std; unsigned N, Q; cin >> N >> Q; vector A(N); for (auto &a : A) cin >> a; unordered_map value_to_rank_lower, value_to_rank_upper; { vector tmp(A); ranges::sort(tmp); for (unsigned i{}; i < size(tmp); i++) { value_to_rank_upper[tmp[i]] = i; if (!value_to_rank_lower.contains(tmp[i])) value_to_rank_lower[tmp[i]] = i; } } for (unsigned i{}; i < Q; i++) { unsigned x, y; cin >> x >> y; --x; --y; cout << (value_to_rank_lower[A[x]] - min(value_to_rank_upper[A[y]] + 1, value_to_rank_lower[A[x]])) << endl; } return 0; }