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;
long long c[1000005], cnt[1000005], ans;
long long n, m, k, len;
long long num[1000005];
inline long long read() {
  long long res = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
  return res * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct Query {
  long long l, r, bl, id;
  inline bool operator<(const Query &a) const {
    if (!(bl ^ a.bl)) {
      return r < a.r;
    }
    return bl < a.bl;
  }
} q[1000005];
inline void ins(long long x) {
  if (cnt[c[x]] == c[x] - 1) ans++;
  if (cnt[c[x]] == c[x]) ans--;
  cnt[c[x]]++;
}
inline void del(long long x) {
  if (cnt[c[x]] == c[x]) ans--;
  if (cnt[c[x]] == c[x] + 1) ans++;
  cnt[c[x]]--;
}
signed main() {
  n = read();
  m = read();
  len = sqrt(n);
  long long flag = 1;
  for (register long long i = 1; i <= n; i++) {
    c[i] = read();
    if (c[i] != c[i - 1] && i != 1) flag = 0;
  }
  if (flag) {
    for (register long long i = 1; i <= m; i++) {
      long long l = read();
      long long r = read();
      long long tmp = r - l + 1;
      if (tmp == c[1])
        cout << 1 << endl;
      else
        puts("0");
    }
    return 0;
  }
  for (register long long i = 1, x, y; i <= m; i++) {
    x = read();
    y = read();
    q[i].l = x;
    q[i].r = y;
    q[i].bl = (x - 1) / len + 1;
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
  long long l = 1, r = 0, x, y;
  for (register long long i = 1; i <= m; ++i) {
    x = q[i].l;
    y = q[i].r;
    while (l < x) del(l++);
    while (l > x) ins(--l);
    while (r < y) ins(++r);
    while (r > y) del(r--);
    num[q[i].id] = ans;
  }
  for (register long long i = 1; i <= m; i++) {
    printf("%d\n", num[i]);
  }
  return 0;
}
