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;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << "," << v.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  long long sz = v.size();
  for (long long i = 0; i < sz; ++i) {
    os << v[i];
    if (i != sz - 1) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  T last = *v.rbegin();
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != last) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  for (auto it : v) {
    os << it.first << " : " << it.second << "\n";
  }
  return os;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % 1000000007;
    }
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return res;
}
long long fact(long long k) {
  if (k == 1 || k == 2) return k;
  long long a = 1, b = 1;
  while (a <= k) {
    b = ((b % 1000000007) * (a % 1000000007)) % 1000000007;
    a++;
  }
  return b;
}
uint64_t toint(const string &s) {
  istringstream src(s);
  uint64_t v;
  src >> v;
  return v;
}
string tostring(uint64_t v) {
  ostringstream src;
  src << v;
  return src.str();
}
const long long N = 100005;
long long n, q;
long long curr_ans, cnt[N];
long long BS = 555;
long long arr[N];
long long ans[N];
pair<pair<long long, long long>, long long> query[N];
inline bool mocmp(pair<pair<long long, long long>, long long> &p1,
                  pair<pair<long long, long long>, long long> &p2) {
  if (p1.first.first / BS != p2.first.first / BS)
    return p1.first.first < p2.first.first;
  return p1.first.second < p2.first.second;
}
inline void add(long long x) {
  if (x > 100000) return;
  if (cnt[x] == x - 1) curr_ans++;
  if (cnt[x] == x) curr_ans--;
  cnt[x]++;
}
inline void remove(long long x) {
  if (x > 100000) return;
  if (cnt[x] == x + 1) curr_ans++;
  if (cnt[x] == x) curr_ans--;
  cnt[x]--;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  BS = ceil(sqrt(n));
  for (__typeof(0) i = 0; i <= n - 1; i++) cin >> arr[i];
  for (__typeof(0) i = 0; i <= q - 1; i++) {
    cin >> query[i].first.first >> query[i].first.second;
    query[i].second = i;
  }
  sort(query, query + q, mocmp);
  long long mo_left = 0, mo_right = -1;
  for (__typeof(0) i = 0; i <= q - 1; i++) {
    long long left = query[i].first.first - 1;
    long long right = query[i].first.second - 1;
    long long id = query[i].second;
    while (mo_right < right) {
      add(arr[++mo_right]);
    }
    while (mo_right > right) {
      remove(arr[mo_right--]);
    }
    while (mo_left < left) {
      remove(arr[mo_left++]);
    }
    while (mo_left > left) {
      add(arr[--mo_left]);
    }
    ans[id] = curr_ans;
  }
  for (__typeof(0) i = 0; i <= q - 1; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
