#include <bits/stdc++.h>
using namespace std;
int n, a[100500], i, b[100500], m, j, ans, l, r, k, len, kol[500][100500],
    c[1000];
int main() {
  scanf("%d%d\n", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  scanf("\n");
  sort(b + 1, b + n + 1);
  for (i = 1; i <= n; i++) {
    k++;
    if (b[i] != b[i + 1]) {
      if (k >= b[i]) {
        len++;
        c[len] = b[i];
      }
      k = 0;
    }
  }
  for (i = 1; i <= len; i++) {
    for (j = 1; j <= n; j++) {
      kol[i][j] = kol[i][j - 1];
      if (a[j] == c[i]) kol[i][j]++;
    }
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d\n", &l, &r);
    ans = 0;
    for (j = 1; j <= len; j++) {
      if (kol[j][r] - kol[j][l - 1] == c[j]) ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
