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;
typedef char* cstr;
const int oo = (~0u) >> 1;
const long long int ooll = (~0ull) >> 1;
const double inf = 1e8;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <typename type>
inline bool cmax(type& a, const type& b) {
  return a < b ? a = b, true : false;
}
template <typename type>
inline bool cmin(type& a, const type& b) {
  return a > b ? a = b, true : false;
}
template <typename type>
inline type sqr(const type& first) {
  return first * first;
}
int dbcmp(const double& a, const double& b) {
  return (a > b + eps) - (a < b - eps);
}
int sgn(const double& first) { return dbcmp(first, 0); }
template <typename type>
inline type lb(type first) {
  return first & (-first);
}
template <typename type>
inline void bit_inc(vector<type>& st, int first, type inc) {
  while (first < ((int)(st).size())) st[first] += inc, first += lb(first);
}
template <typename type>
inline type bit_sum(const vector<type>& st, int first) {
  type s = 0;
  while (first > 0) s += st[first], first -= lb(first);
  return s;
}
inline void make_set(vector<int>& set, int size) {
  set.resize(size);
  for (int i = 0; i < (size); ++i) set[i] = i;
}
inline int find_set(vector<int>& set, int first) {
  if (set[first] != first) set[first] = find_set(set, set[first]);
  return set[first];
}
inline bool union_set(vector<int>& set, int a, int b) {
  a = find_set(set, a), b = find_set(set, b);
  return a == b ? false : set[a] = b, true;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  vector<int> c(n + 1);
  for (int i = 0; i < (n); ++i)
    if (a[i] <= n) c[a[i]]++;
  vector<int> p(n + 1);
  vector<int> b;
  for (int i = (1); i <= (n); ++i)
    if (c[i] >= i) p[i] = ((int)(b).size()), b.push_back(i);
  vector<vector<int> > d(((int)(b).size()));
  for (int i = 0; i < (n); ++i)
    if (a[i] <= n && c[a[i]] >= a[i]) d[p[a[i]]].push_back(i);
  for (int i = 0; i < (((int)(b).size())); ++i) d[i].push_back(n);
  for (int q = 0; q < (m); ++q) {
    int l, r;
    cin >> l >> r;
    int ans = 0;
    for (int i = 0; i < (((int)(b).size())); ++i) {
      int L = lower_bound(d[i].begin(), d[i].end(), l - 1) - d[i].begin();
      if (L + b[i] < ((int)(d[i]).size()) && d[i][L + b[i]] >= r &&
          d[i][L + b[i] - 1] < r)
        ans++;
    }
    cout << ans << endl;
  }
}
