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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAXN = 100005;
const int LMAXN = 20;
inline int64_t gilbertOrder(int x, int y, int pow, int rotate) {
  if (pow == 0) {
    return 0;
  }
  int hpow = 1 << (pow - 1);
  int seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2);
  seg = (seg + rotate) & 3;
  const int rotateDelta[4] = {3, 0, 0, 1};
  int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
  int nrot = (rotate + rotateDelta[seg]) & 3;
  int64_t subSquareSize = int64_t(1) << (2 * pow - 2);
  int64_t ans = seg * subSquareSize;
  int64_t add = gilbertOrder(nx, ny, pow - 1, nrot);
  ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
  return ans;
}
struct Query {
  int l, r, ind;
  int64_t ord;
  inline void calcOrder() { ord = gilbertOrder(l, r, LMAXN, 0); }
};
inline bool operator<(const Query &a, const Query &b) { return a.ord < b.ord; }
int n, m, a[MAXN], vx, ret[MAXN];
int ans[MAXN];
int curr, cc[MAXN];
vector<Query> q;
map<int, int> ma;
set<int> ss;
inline void add(int x) {
  cc[x]++;
  if (cc[x] == ret[x])
    curr++;
  else if (cc[x] == ret[x] + 1)
    curr--;
}
inline void remove(int x) {
  if (cc[x] == ret[x]) curr--;
  if (cc[x] == ret[x] + 1) curr++;
  cc[x]--;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i], ss.insert(a[i]);
  for (auto it : ss) ma[it] = vx++;
  for (int i = 0; i < n; i++) ret[ma[a[i]]] = a[i], a[i] = ma[a[i]];
  q.resize(m);
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    q[i].l = l - 1;
    q[i].r = r - 1;
    q[i].ind = i;
    q[i].calcOrder();
  }
  sort(q.begin(), q.end());
  int mo_left = 0, mo_right = -1;
  for (int i = 0; i < m; i++) {
    int left = q[i].l;
    int right = q[i].r;
    while (mo_right < right) add(a[++mo_right]);
    while (mo_right > right) remove(a[mo_right--]);
    while (mo_left < left) remove(a[mo_left++]);
    while (mo_left > left) add(a[--mo_left]);
    ans[q[i].ind] = curr;
  }
  for (int i = 0; i < m; i++) cout << ans[i] << "\n";
  return 0;
}
