#include <bits/stdc++.h>
using namespace std;
int N, M, T;
int a[100005], co[100005], b[100005], ans[100005];
vector<pair<int, int> > v;
int main() {
  int i, j, k;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= N; i++) {
    scanf("%d", &a[i]);
    if (a[i] <= 100000) co[a[i]]++;
  }
  int x, y;
  for (i = 0; i < M; i++) scanf("%d%d", &x, &y), v.push_back(make_pair(x, y));
  for (i = 1; i <= 100000; i++) {
    if (co[i] >= i) {
      for (j = 1; j <= N; j++) b[j] = b[j - 1] + (a[j] == i);
      for (j = 0; j < M; j++)
        if (b[v[j].second] - b[v[j].first - 1] == i) ans[j]++;
    }
  }
  for (i = 0; i < M; i++) printf("%d\n", ans[i]);
}
