#include <bits/stdc++.h>
using namespace std;
const int DIM = 100010;
int arr[DIM], ans[DIM], psm[DIM];
pair<int, int> qry[DIM];
map<int, vector<int>> mmp;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    mmp[arr[i]].push_back(i);
  }
  for (int i = 1; i <= m; i++) cin >> qry[i].first >> qry[i].second;
  for (pair<int, vector<int>> lst : mmp) {
    if (lst.first > lst.second.size()) continue;
    fill(psm + 1, psm + n + 1, 0);
    for (int x : lst.second) psm[x]++;
    for (int i = 1; i <= n; i++) psm[i] += psm[i - 1];
    for (int i = 1; i <= m; i++) {
      if (psm[qry[i].second] - psm[qry[i].first - 1] == lst.first) ans[i]++;
    }
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
  return 0;
}
