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;
map<int, vector<int> > ma;
pair<int, vector<int> > indices[100005];
int LEFT = 0, RIGHT = 1;
int binary(int start, int end, int pos, int index, int flag) {
  if (end - start <= 1) {
    if (flag == LEFT) {
      if (indices[pos].second[start] >= index) return start;
      if (indices[pos].second[end] >= index) return end;
      return -1;
    } else {
      if (indices[pos].second[end] <= index) return end;
      if (indices[pos].second[start] <= index) return start;
      return -1;
    }
  }
  int mid = (start + end) / 2;
  if (flag == LEFT) {
    if (indices[pos].second[mid] >= index)
      return binary(start, mid, pos, index, flag);
    return binary(mid + 1, end, pos, index, flag);
  }
  if (indices[pos].second[mid + 1] <= index)
    return binary(mid + 1, end, pos, index, flag);
  return binary(start, mid, pos, index, flag);
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    auto it = ma.find(a);
    if (it == ma.end()) {
      vector<int> v;
      v.push_back(i);
      ma.insert(make_pair(a, v));
    } else
      it->second.push_back(i);
  }
  int pos = 0;
  for (auto it = ma.begin(); it != ma.end(); it++) {
    if (it->second.size() >= it->first) {
      indices[pos].first = it->first;
      indices[pos].second = it->second;
      pos++;
    }
  }
  while (m--) {
    int l, r;
    scanf("%d", &l);
    scanf("%d", &r);
    int ans = 0;
    for (int i = 0; i <= pos - 1; i++) {
      int left = binary(0, (int)indices[i].second.size() - 1, i, l, LEFT);
      if (left != -1) {
        int right = binary(0, (int)indices[i].second.size() - 1, i, r, RIGHT);
        if (right != -1 && left <= right) {
          if (right - left + 1 == indices[i].first) ans++;
        }
      }
    }
    printf("%d", ans);
    ;
    printf("\n");
  }
  return 0;
}
