#include <bits/stdc++.h>
using namespace std;
const long long N = 100010;
long long a[N], b[N], cnt[N], l[N], r[N], ans[N], n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] <= n) cnt[a[i]]++;
  }
  for (int i = 1; i <= m; i++) cin >> l[i] >> r[i];
  for (int i = 1; i <= n; i++)
    if (i <= cnt[i]) {
      for (int j = 1; j <= n; j++) b[j] = b[j - 1] + (a[j] == i);
      for (int j = 1; j <= m; j++)
        if (b[r[j]] - b[l[j] - 1] == i) ans[j]++;
    }
  for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
