#include using namespace std; using lint = long long; int main() { int n, q; cin >> n >> q; vector> kyori(n); vector pos(n); for (int i = 0; i < n; i++) { int a; cin >> a; kyori[i] = {a, i}; } sort(kyori.begin(), kyori.end()); for (int i = 0; i < n; i++) { pos[kyori[i].second] = i; } while (q--) { int x, y; cin >> x >> y; x--, y--; cout << max(0, pos[x]-pos[y]-1) << endl; } }