#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 5;
int a[MAXN], cnt[MAXN], c[MAXN], l[MAXN], r[MAXN], ans[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] <= n) cnt[a[i]]++;
  }
  for (int i = 0; i < m; i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = 1; i <= n; i++) {
    if (cnt[i] < i) continue;
    c[0] = 0;
    for (int j = 1; j <= n; j++) {
      if (a[j] == i)
        c[j] = c[j - 1] + 1;
      else
        c[j] = c[j - 1];
    }
    for (int j = 0; j < m; j++)
      if (c[r[j]] - c[l[j] - 1] == i) ans[j]++;
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
