#include using namespace std; using ll = long long; #define rep(i, n) for(int i = 0; i < n; i++) int main() { int N, Q; cin >> N >> Q; vector a(N), b; rep(i, N) cin >> a[i]; b = a; sort(b.begin(), b.end()); rep(i, Q) { int x, y; cin >> x >> y; x--; y--; int ans = 0; if(a[x] > a[y]) { ans = lower_bound(b.begin(), b.end(), a[x]) - upper_bound(b.begin(), b.end(), a[y]); } cout << ans << endl; } }