#include <bits/stdc++.h>
using namespace std;
const long long mx = 1e5 + 10;
long long n, m, a[mx], cnt[mx], r[mx], l[mx], p[mx], ans[mx];
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mx) cnt[a[i]]++;
  }
  for (long long i = 0; i < m; i++) cin >> l[i] >> r[i];
  for (long long in = 1; in < mx; in++) {
    if (cnt[in] >= in) {
      p[0] = 0;
      for (long long i = 1; i <= n; i++) p[i] = p[i - 1] + (a[i] == in);
      for (long long i = 0; i < m; i++)
        ans[i] += ((p[r[i]] - p[l[i] - 1]) == in);
    }
  }
  for (long long i = 0; i < m; i++) cout << ans[i] << endl;
  return 0;
}
