#include <bits/stdc++.h>
using namespace std;
map<int, int> g;
int n, m;
int x[100020], y[100020], z[100020], a[100020], s[100020];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), g[a[i]]++;
  for (int i = 0; i < m; i++) scanf("%d %d", x + i, y + i);
  for (__typeof(g.begin()) i = g.begin(); i != g.end(); i++) {
    if (i->first > i->second) continue;
    for (int j = 1; j <= n; j++)
      if (a[j] == i->first)
        s[j] = s[j - 1] + 1;
      else
        s[j] = s[j - 1];
    for (int j = 0; j < m; j++)
      if (s[y[j]] - s[x[j] - 1] == i->first) z[j]++;
  }
  for (int i = 0; i < m; i++) printf("%d\n", z[i]);
  return 0;
}
