#include using namespace std; long long A[100005]; int main() { int N, Q; cin >> N >> Q; for (int i = 1; i <= N; i++) cin >> A[i]; while (Q--) { int x, y; cin >> x >> y; if (A[x] <= A[y]) { cout << 0 << "\n"; } else { int cnt = 0; for (int i = 1; i <= N; i++) { if (A[y] < A[i] && A[i] < A[x]) cnt++; } cout << cnt << "\n"; } } return 0; }