#include <bits/stdc++.h>
using namespace std;
int n, m, l[100001], r[100001], ans[100001], a[100001], s[100001], b[100001];
int main() {
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
    if (a[i] <= m) b[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 1; i <= m; i++) {
    if (b[i] >= i) {
      for (int j = 1; j <= m; j++) {
        s[j] = s[j - 1] + (a[j] == i);
      }
      for (int j = 1; j <= n; j++)
        if (s[r[j]] - s[l[j] - 1] == i) ans[j]++;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << endl;
  return 0;
}
