#include #include using namespace std; using namespace atcoder; using ll = long long; #define rep(i, s, n) for(int i = s; i < (int)(n); i++) #define repr(i, s, n) for(int i = ((int)(n) - 1); i >= s; i--) #define sz(x) ((int)(x).size()) #define inf_int (int) (1e9 + 7) #define inf_ll (ll) (1e+18) int main(){ ll n, q; cin >> n >> q; vector a(n); rep(i, 0, n){ cin >> a[i]; } vector b = a; // コピー sort(b.begin(), b.end()); // b を小さい順にソート b.erase(unique(b.begin(), b.end()), b.end()); // b から重複を除去する vector res(a.size()); for (int i = 0; i < a.size(); ++i) res[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); rep(i, 0, q){ ll x, y; cin >> x >> y; x--; y--; cout << max((ll) 0, res[x] - res[y] - 1) << endl; } }