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;
struct node {
  int l;
  int r;
  int k;
};
const int N = 1e5 + 5;
int n, q, a, b, l, r, k, s, answer = 0;
int arr[N], ans[N], cnt[N];
vector<struct node> queries;
void add(int index) {
  if (arr[index] <= n + 3) {
    ++cnt[arr[index]];
    if (cnt[arr[index]] == arr[index]) {
      ++answer;
    } else if (cnt[arr[index]] == arr[index] + 1) {
      --answer;
    }
  }
}
void remove(int index) {
  if (arr[index] <= n + 3) {
    --cnt[arr[index]];
    if (cnt[arr[index]] == arr[index]) {
      ++answer;
    } else if (cnt[arr[index]] == arr[index] - 1) {
      --answer;
    }
  }
}
bool comp(struct node& a, struct node& b) {
  int b1 = a.l / s, b2 = b.l / s;
  if (b1 < b2) {
    return true;
  } else if (b1 == b2) {
    return a.r < b.r;
  }
  return false;
}
int main(void) {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  s = (int)ceil(sqrt(n));
  for (int i = 0; i <= n - 1; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i <= q - 1; ++i) {
    cin >> a >> b;
    --a, --b;
    queries.push_back({a, b, i});
  }
  sort(queries.begin(), queries.end(), comp);
  a = b = 0;
  add(a);
  for (int i = 0; i <= q - 1; ++i) {
    l = queries[i].l;
    r = queries[i].r;
    k = queries[i].k;
    while (a < l) {
      remove(a);
      ++a;
    }
    while (a > l) {
      add(a - 1);
      --a;
    }
    while (b > r) {
      remove(b);
      --b;
    }
    while (b < r) {
      add(b + 1);
      ++b;
    }
    ans[k] = answer;
  }
  for (int i = 0; i <= q - 1; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
