The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. 

Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.

Help the Little Elephant to count the answers to all queries.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).

Output

In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.

Examples

Input

7 2
3 1 2 2 3 3 7
1 7
3 4


Output

3
1
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > v;
int counta = 0;
unordered_map<int, int> m;
long long ans[1000001];
int arr[1000001];
int sqrtn;
bool func(pair<int, pair<int, int> > p1, pair<int, pair<int, int> > p2) {
  int l1 = p1.second.first;
  int r1 = p1.second.second;
  int l2 = p2.second.first;
  int r2 = p2.second.second;
  if (l1 / sqrtn < l2 / sqrtn)
    return 1;
  else if (l1 / sqrtn == l2 / sqrtn && r1 < r2)
    return 1;
  return 0;
}
void add(int a) {
  m[a]++;
  if (m[a] == a) counta++;
  if (m[a] == a + 1) counta--;
}
void removee(int a) {
  if (m[a] == a) {
    counta--;
  } else if (m[a] == a + 1) {
    counta++;
  }
  m[a]--;
}
int main() {
  int n, q;
  cin >> n;
  cin >> q;
  sqrtn = (sqrt(n));
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
  }
  int a, b;
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &a, &b);
    v.push_back(make_pair(i, make_pair(a, b)));
  }
  sort(v.begin(), v.end(), func);
  int mo_l = 0, mo_r = -1;
  for (int i = 0; i < q; ++i) {
    int ll = v[i].second.first - 1;
    int rr = v[i].second.second - 1;
    while (mo_r < rr) {
      mo_r++;
      add(arr[mo_r]);
    }
    while (mo_r > rr) {
      removee(arr[mo_r]);
      mo_r--;
    }
    while (mo_l > ll) {
      mo_l--;
      add(arr[mo_l]);
    }
    while (mo_l < ll) {
      removee(arr[mo_l]);
      mo_l++;
    }
    ans[v[i].first] = counta;
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << "\n";
  }
}
