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 query {
  int l, r, ID;
} Q[100000];
int n, q, idx, SQRT, cur_ans;
int a[100000];
int cnt[100001];
int answer[100000];
bool mo_cmp(const query &a, const query &b) {
  int x = a.l / SQRT;
  int y = b.l / SQRT;
  if (x == y) return a.r < b.r;
  return x < y;
}
inline void add(int idx) {
  if (a[idx] > 100000) return;
  if (cnt[a[idx]] == a[idx]) cur_ans--;
  cnt[a[idx]]++;
  if (cnt[a[idx]] == a[idx]) cur_ans++;
}
inline void remove(int idx) {
  if (a[idx] > 100000) return;
  if (cnt[a[idx]] == a[idx]) cur_ans--;
  cnt[a[idx]]--;
  if (cnt[a[idx]] == a[idx]) cur_ans++;
}
int main() {
  if (0) {
    cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> a[i];
  } else {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; i++) scanf("%d", a + i);
  }
  for (int i = 0; i < q; i++) {
    if (0)
      cin >> Q[i].l >> Q[i].r;
    else
      scanf("%d%d", &Q[i].l, &Q[i].r);
    Q[i].l--;
    Q[i].r--;
    Q[i].ID = i;
  }
  SQRT = (int)(sqrt(n + 1.0));
  sort(Q, Q + q, mo_cmp);
  memset(cnt, 0, sizeof cnt);
  int mo_left = 0;
  int mo_right = -1;
  for (int i = 0; i < q; i++) {
    int L = Q[i].l;
    int R = Q[i].r;
    while (mo_right < R) {
      mo_right++;
      add(mo_right);
    }
    while (R < mo_right) {
      remove(mo_right);
      mo_right--;
    }
    while (mo_left < L) {
      remove(mo_left);
      mo_left++;
    }
    while (L < mo_left) {
      mo_left--;
      add(mo_left);
    }
    answer[Q[i].ID] = cur_ans;
  }
  if (0)
    for (int i = 0; i < q; i++) cout << answer[i] << '\n';
  else
    for (int i = 0; i < q; i++) printf("%d\n", answer[i]);
  return 0;
}
