#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn], ans[maxn], n, m, num[maxn], l[maxn], r[maxn];
map<int, int> cnt;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= m; i++) cin >> l[i] >> r[i];
  for (int i = 1; i <= n; i++) {
    if (cnt[i] < i) continue;
    for (int j = 1; j <= n; j++) {
      num[j] = num[j - 1];
      if (a[j] == i) num[j]++;
    }
    for (int j = 1; j <= m; j++)
      if (num[r[j]] - num[l[j] - 1] == i) ans[j]++;
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << endl;
  }
}
