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;
int const sqN = 320;
int add(int a, int b);
int sub(int a, int b);
int arr[100005];
struct query {
  int index;
  int l;
  int r;
  int ans;
};
bool comp(query &a, query &b) {
  if (a.l / sqN != b.l / sqN) {
    return a.l / sqN < b.l / sqN;
  }
  return a.r < b.r;
}
bool comp_by_index(query &a, query &b) { return a.index < b.index; }
int main() {
  int n, m, aux, l, r, cnt;
  cin >> n >> m;
  vector<int> F;
  F.push_back(0);
  for (int i = 0; i < n; i++) {
    cin >> aux;
    if (aux > 100000) aux = 0;
    F.push_back(aux);
  }
  vector<query> Q;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    query inp;
    inp.index = i;
    inp.l = l;
    inp.r = r;
    Q.push_back(inp);
  }
  sort(Q.begin(), Q.end(), comp);
  memset(arr, 0, sizeof(arr));
  r = 1;
  l = 0;
  cnt = (F[1] == 1) ? 1 : 0;
  arr[F[1]] += 1;
  for (int i = 0; i < m; i++) {
    query curq = Q[i];
    while (r < Q[i].r) {
      r++;
      cnt += sub(arr[F[r]], F[r]);
      arr[F[r]] += 1;
      cnt += add(arr[F[r]], F[r]);
    }
    while (l < Q[i].l - 1) {
      l++;
      cnt += sub(arr[F[l]], F[l]);
      arr[F[l]] -= 1;
      cnt += add(arr[F[l]], F[l]);
    }
    while (l >= Q[i].l) {
      cnt += sub(arr[F[l]], F[l]);
      arr[F[l]] += 1;
      cnt += add(arr[F[l]], F[l]);
      l--;
    }
    while (r > Q[i].r) {
      cnt += sub(arr[F[r]], F[r]);
      arr[F[r]] -= 1;
      cnt += add(arr[F[r]], F[r]);
      r--;
    }
    Q[i].ans = cnt;
  }
  sort(Q.begin(), Q.end(), comp_by_index);
  for (int i = 0; i < Q.size(); i++) cout << Q[i].ans << endl;
}
int add(int a, int b) {
  if (b > 0 and b == a) return 1;
  return 0;
}
int sub(int a, int b) {
  if (b > 0 and b == a) return -1;
  return 0;
}
