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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = ((res % 1000000007) * (a % 1000000007)) % 1000000007;
    }
    b = b >> 1;
    a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
  }
  return res;
}
struct query {
  int l, r, in;
} q[100005];
const int blk_size = 318;
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> q[i].l >> q[i].r;
    q[i].l--;
    q[i].r--;
    q[i].in = i;
  }
  sort(q, q + m, [](query a, query b) -> bool {
    if ((a.l / blk_size) != (b.l / blk_size))
      return (a.l / blk_size) < (b.l / blk_size);
    return a.r < b.r;
  });
  unordered_map<int, int> ma;
  unordered_set<int> se;
  vector<int> ans(m);
  int ml = 0, mr = -1, currAns = 0;
  for (int i = 0; i < m; i++) {
    while (q[i].l > ml) {
      ma[a[ml]]--;
      if (ma[a[ml]] == a[ml]) {
        currAns += 1;
        se.insert(a[ml]);
      } else if (se.find(a[ml]) != se.end()) {
        se.erase(a[ml]);
        currAns--;
      }
      ml++;
    }
    while (q[i].l < ml) {
      ml--;
      ma[a[ml]]++;
      if (ma[a[ml]] == a[ml]) {
        currAns += 1;
        se.insert(a[ml]);
      } else if (se.find(a[ml]) != se.end()) {
        se.erase(a[ml]);
        currAns--;
      }
    }
    while (q[i].r > mr) {
      mr++;
      ma[a[mr]]++;
      if (ma[a[mr]] == a[mr]) {
        currAns += 1;
        se.insert(a[mr]);
      } else if (se.find(a[mr]) != se.end()) {
        se.erase(a[mr]);
        currAns--;
      }
    }
    while (q[i].r < mr) {
      ma[a[mr]]--;
      if (ma[a[mr]] == a[mr]) {
        currAns += 1;
        se.insert(a[mr]);
      } else if (se.find(a[mr]) != se.end()) {
        se.erase(a[mr]);
        currAns--;
      }
      mr--;
    }
    ans[q[i].in] = currAns;
  }
  for (int i : ans) {
    cout << i << endl;
  }
  return 0;
}
