#include using namespace std; int main() { int n, q; cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector b = a; sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); while (q--) { int x, y; cin >> x >> y; x--; y--; int ix = lower_bound(b.begin(), b.end(), a[x]) - b.begin(); int iy = lower_bound(b.begin(), b.end(), a[y]) - b.begin(); int ans = max(0, ix - iy - 1); cout << ans << endl; } }