#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++) { if (i != 0 && kyori[i-1].second == kyori[i].second) pos[kyori[i].second] = pos[kyori[i-1].second]; else pos[kyori[i].second] = i; } while (q--) { int x, y; cin >> x >> y; x--, y--; cout << max(0, pos[x]-pos[y]-1) << endl; } }