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>
inline long long gilbert_order(int x, int y, int pow, int rotate) {
  if (pow == 0) {
    return 0;
  }
  int hpow = 1 << (pow - 1);
  int seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2);
  seg = (seg + rotate) & 3;
  const int rotateDelta[4] = {3, 0, 0, 1};
  int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
  int nrot = (rotate + rotateDelta[seg]) & 3;
  long long subSquareSize = 1LL << (2 * pow - 2);
  long long ans = seg * subSquareSize;
  long long add = gilbert_order(nx, ny, pow - 1, nrot);
  ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
  return ans;
}
const int MAX_N = 1e5 + 7;
struct bg_query {
  int l, r, id;
  long long ord;
  bool operator<(const bg_query& o) const { return ord < o.ord; }
} qs[MAX_N];
int ans[MAX_N], a[MAX_N];
int in[MAX_N];
static inline void setio(void);
int main(void) {
  setio();
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  for (int i = 0; i < q; ++i) {
    std::cin >> qs[i].l >> qs[i].r;
    qs[i].id = i;
    qs[i].ord = gilbert_order(--qs[i].l, --qs[i].r, 21, 0);
  }
  std::sort(qs, qs + q);
  int earliest_in = 0, latest_in = -1, cnt = 0;
  std::function<void(const int&)> add = [&](const int& i) {
    if (a[i] >= MAX_N) return;
    ++in[a[i]];
    if (in[a[i]] - 1 == a[i])
      --cnt;
    else if (in[a[i]] == a[i])
      ++cnt;
  };
  std::function<void(const int&)> rem = [&](const int& i) {
    if (a[i] >= MAX_N) return;
    --in[a[i]];
    if (in[a[i]] + 1 == a[i])
      --cnt;
    else if (in[a[i]] == a[i])
      ++cnt;
  };
  for (int i = 0; i < q; ++i) {
    for (; earliest_in < qs[i].l; ++earliest_in) rem(earliest_in);
    for (; earliest_in > qs[i].l; --earliest_in) add(earliest_in - 1);
    for (; latest_in < qs[i].r; ++latest_in) add(latest_in + 1);
    for (; latest_in > qs[i].r; --latest_in) rem(latest_in);
    ans[qs[i].id] = cnt;
  }
  for (int i = 0; i < q; ++i) std::cout << ans[i] << "\n";
  return 0;
}
static inline void setio(void) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(10);
  std::cout << std::fixed;
}
