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;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
template <class T>
inline T bigMod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T>
inline string int2String(T a) {
  ostringstream str;
  str << a;
  return str.str();
}
template <class T>
inline T string2int(string a) {
  stringstream str(a);
  T b;
  str >> b;
  return b;
}
template <class T>
inline void read(T& r) {
  r = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' or ch > '9') {
    f = (ch == '-' ? -1 : 1), ch = getchar();
  }
  while (ch >= '0' and ch <= '9') {
    r = r * 10 + ch - '0', ch = getchar();
  }
  r *= f;
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
struct query {
  int l, r, id;
} Q[100005];
const int k = 320;
int ara[100005];
unordered_map<int, int> cnt;
bool cmp(query& a, query& b) {
  int b1 = a.l / k, b2 = b.l / k;
  if (b1 == b2) return a.r < b.r;
  return b1 < b2;
}
int l = 0, r = -1, sum = 0, ans[100005];
void Add(int x) {
  x = ara[x];
  if (cnt[x] == x) sum--;
  cnt[x]++;
  if (cnt[x] == x) sum++;
}
void Del(int x) {
  x = ara[x];
  if (cnt[x] == x) sum--;
  cnt[x]--;
  if (cnt[x] == x) sum++;
}
int main() {
  int q, n;
  scanf("%d %d", &n, &q);
  for (int i = int(0); i < int(n); i++) scanf("%d", &ara[i]);
  for (int i = int(0); i < int(q); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--, y--;
    Q[i].l = x, Q[i].r = y;
    Q[i].id = i;
  }
  sort(Q, Q + q, cmp);
  for (int i = int(0); i < int(q); i++) {
    while (l > Q[i].l) Add(--l);
    while (r < Q[i].r) Add(++r);
    while (l < Q[i].l) Del(l++);
    while (r > Q[i].r) Del(r--);
    ans[Q[i].id] = sum;
  }
  for (int i = int(0); i < int(q); i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
