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 lazy;
  int sum;
};
node tree[(1 << 20)];
void put(int l, int r, int val, int p = 1, int s = 1, int e = 100001) {
  if (s == e) {
    tree[p].sum += val;
    return;
  }
  if (s >= l && e <= r) {
    tree[p].lazy += val;
    tree[p].sum += (val * (e - s + 1));
    return;
  }
  int mid = (s + e) / 2;
  if (l <= mid) {
    put(l, r, val, p * 2, s, mid);
  }
  if (r > mid) {
    put(l, r, val, p * 2 + 1, mid + 1, e);
  }
}
int get(int idx, int p = 1, int s = 1, int e = 100001) {
  if (s == e) {
    return tree[p].sum;
  }
  int mid = (s + e) / 2;
  tree[p * 2].sum += (tree[p].lazy * (mid - s + 1));
  tree[p * 2].lazy += tree[p].lazy;
  tree[p * 2 + 1].sum += (tree[p].lazy * (e - mid));
  tree[p * 2 + 1].lazy += tree[p].lazy;
  tree[p].lazy = 0;
  int ret = 0;
  if (idx <= mid) {
    ret = get(idx, p * 2, s, mid);
  }
  if (idx > mid) {
    ret = get(idx, p * 2 + 1, mid + 1, e);
  }
  tree[p].sum = tree[p * 2].sum + tree[p * 2 + 1].sum;
  return ret;
}
vector<pair<pair<int, int>, int> > Q;
vector<vector<int> > num(100001);
int arr[100001];
int ans[100001];
int main() {
  int n, m, a;
  int l, r;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    arr[i] = a;
    if (a <= (int)1e5) {
      num[a].push_back(i);
      if (num[a].size() == a) {
        put(i, n, 1);
      } else if (num[a].size() == a + 1) {
        put(i, n, -1);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &l, &r);
    Q.push_back(make_pair(make_pair(l, r), i));
  }
  sort(Q.begin(), Q.end());
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (j < Q.size() && Q[j].first.first == i) {
      ans[Q[j].second] = get(Q[j].first.second);
      i--;
      j++;
    } else if (arr[i] <= (int)1e5) {
      a = arr[i];
      int idx = lower_bound(num[a].begin(), num[a].end(), i) - num[a].begin();
      if (idx + a - 1 < num[a].size()) {
        if (idx + a - 1 == num[a].size() - 1)
          put(num[a][idx + a - 1], n, -1);
        else if (idx + a - 1 < num[a].size() - 1)
          put(num[a][idx + a - 1], num[a][idx + a] - 1, -1);
        if (idx + a == num[a].size() - 1)
          put(num[a][idx + a], n, 1);
        else if (idx + a < num[a].size())
          put(num[a][idx + a], num[a][idx + a + 1] - 1, 1);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d\n", ans[i]);
  }
}
