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 <class _T>
inline void ina(_T a[], int n) {
  int i;
  for (i = 0; i < n; i++) cin >> a[i];
}
template <class _T>
inline void outa(_T a[], int n) {
  int i;
  for (i = 0; i < n - 1; i++) cout << a[i], cout << " ";
  if (i) printf("%d", i);
  cout << "\n";
}
const double EPS = 1e-9;
const int SIZE = 1e6;
template <class _T>
inline _T pow(_T a, _T b, _T m) {
  a %= m;
  _T ans = 1 % m;
  while (b) {
    if (b & 1) ans *= a, ans %= m;
    a *= a;
    a %= m;
    b >>= 1;
  }
  return ans;
}
template <class _T>
inline _T pow(_T a, _T b) {
  _T ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b >>= 1;
  }
  return ans;
}
template <class _T>
inline _T add(_T a, _T b, _T m) {
  return a >= m - b ? a - (m - b) : a + b;
}
template <class _T>
inline _T multiply(_T a, _T b, _T m) {
  _T ans = 0;
  if (b > a) swap(a, b);
  while (b) {
    if (b & 1) ans = add(ans, a, m);
    b >>= 1;
    a = add(a, a, m);
  }
  return ans;
}
template <class _T>
inline _T bigpow(_T a, _T b, _T m) {
  a %= m;
  _T ans = 1 % m;
  while (b) {
    if (b & 1) ans = multiply(ans, a, m);
    a = multiply(a, a, m);
    b >>= 1;
  }
  return ans;
}
template <class _T>
inline _T modinvers(_T a, _T m) {
  return m > 2000000000LL ? bigpow(a, m - 2, m) : pow(a, m - 2, m);
}
template <class _T>
_T _egcd(_T a, _T b, _T &x, _T &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  _T _g = _egcd(b, a % b, x, y);
  _T xt = x;
  x = y, y = xt - (a / b) * y;
  return _g;
}
template <class _T>
inline _T fmodinvers(_T a, _T m) {
  _T x, y;
  _egcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
template <class _T>
inline _T _lcm(_T a, _T b) {
  return (a * b) / __gcd(a, b);
}
template <class _T>
inline _T naturalSum(_T n) {
  return (n * (n + 1)) / 2;
}
template <class _T>
inline _T sqrSum(_T n) {
  return (n * (n + 1) * (2 * n + 1)) / 6;
}
template <class _T>
inline _T cubeSum(_T n) {
  return (((n * (n + 1)) / 2) * ((n * (n + 1)) / 2));
}
template <class _T>
inline _T naturalSum(_T n, _T m) {
  return ((n * (n + 1)) / 2) % m;
}
long long MOD_INV_OF_6;
template <class _T>
inline _T sqrSum(_T n, _T m) {
  n %= m;
  return (((((n * (n + 1)) % m) * (((2 * n) % m + 1) % m)) % m) *
          MOD_INV_OF_6) %
         m;
}
template <class _T>
inline _T cubeSum(_T n, _T m) {
  return ((((n * (n + 1)) / 2) % m) * (((n * (n + 1)) / 2) % m)) % m;
}
int R;
bool C(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first / R == b.first.first / R)
    return a.first.second < b.first.second;
  return a.first.first / R < b.first.first / R;
}
const int MX = 100099;
int i, j, k, x, y, z, n, m, tc, o, l, r;
int a[MX + 5], b[MX + 5], c[MX + 5];
pair<pair<int, int>, int> qry[MX];
int ans[MX];
unordered_map<int, int> F;
int main() {
  scanf("%d %d", &n, &m);
  R = sqrt(n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), F[a[i]] = 0;
  for (i = 0; i < m; i++)
    scanf("%d %d", &qry[i].first.first, &qry[i].first.second),
        qry[i].second = i;
  sort(qry, qry + m, C);
  int cl = 1, cr = 0, cnt = 0;
  for (i = 0; i < m; i++) {
    l = qry[i].first.first;
    r = qry[i].first.second;
    while (cl < l) {
      F[a[cl]]--;
      if (F[a[cl]] == a[cl])
        cnt++;
      else if (F[a[cl]] == a[cl] - 1)
        cnt--;
      cl++;
    }
    while (cr > r) {
      F[a[cr]]--;
      if (F[a[cr]] == a[cr])
        cnt++;
      else if (F[a[cr]] == a[cr] - 1)
        cnt--;
      cr--;
    }
    while (cl > l) {
      cl--;
      F[a[cl]]++;
      if (F[a[cl]] == a[cl])
        cnt++;
      else if (F[a[cl]] == a[cl] + 1)
        cnt--;
    }
    while (cr < r) {
      cr++;
      F[a[cr]]++;
      if (F[a[cr]] == a[cr])
        cnt++;
      else if (F[a[cr]] == a[cr] + 1)
        cnt--;
    }
    ans[qry[i].second] = cnt;
  }
  for (i = 0; i < m; i++) printf("%d", ans[i]), putchar(10);
  return 0;
}
