#include using namespace std; typedef long long ll; typedef pair P; typedef vector

VP; typedef vector VI; typedef vector VVI; #define REP(i, n) for (ll i = 0; i < (n); i++) #define ALL(v) v.begin(), v.end() #define OUT(n) cout << n << "\n" // constexpr ll MOD=998244353; // constexpr ll MOD=1000000007; // constexpr ll INF=2e18; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, Q; cin >> N >> Q; VP A(N); REP(i, N) { cin >> A[i].first; A[i].second = i; } sort(ALL(A)); VI B(N); // i番目の人前にいる人の数 ll cnt = 0; ll prevcnt = 0; ll wait = 0; REP(i, N) { if (i != 0) { if (A[i].first != A[i - 1].first) { cnt += wait; wait = 0; } } else { B[A[i].second] = -1; wait += 1; continue; } wait += 1; B[A[i].second] = prevcnt; prevcnt = cnt; } REP(i, Q) { ll x, y; cin >> x >> y; ll howmany = B[x - 1] - B[y - 1] - 1; if (howmany < 0) { howmany = 0; } OUT(howmany); } }