#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010], l[100010], r[100010], s[100010], ans[100010];
int main() {
  int n, m;
  scanf("%d%d", &m, &n);
  s[0] = 0;
  memset(b, 0, sizeof(b));
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    if (a[i] <= m) b[a[i]]++;
  }
  for (int i = 1; i <= n; i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = 1; i <= m; i++)
    if (i <= b[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++) printf("%d\n", ans[i]);
  return 0;
}
