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;
inline long long read() {
  long long f = 1, r = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    r = (r << 3) + (r << 1) + (ch ^ 48);
    ch = getchar();
  }
  return r * f;
}
inline void write(long long x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
const long long MAXN = 1e6 + 1;
long long n, m, nowans;
long long cnt[MAXN], num[MAXN], pos[MAXN], ans[MAXN];
struct query {
  long long l, r, num;
  bool operator<(const query &t) const {
    return pos[l] ^ pos[t.l] ? pos[l] < pos[t.l] : r < t.r;
  }
} q[MAXN];
inline void change(long long x, long long data) {
  if (num[x] > n) return;
  if (cnt[num[x]] == num[x]) nowans--;
  cnt[num[x]] += data;
  if (cnt[num[x]] == num[x]) nowans++;
}
int main() {
  n = read();
  m = read();
  long long sz = sqrt(n);
  for (register size_t i = 1; i <= n; i++) {
    num[i] = read();
    pos[i] = i / sz;
  }
  for (register size_t i = 1; i <= m; i++) {
    q[i].l = read();
    q[i].r = read();
    q[i].num = i;
  }
  sort(q + 1, q + 1 + m);
  long long nowl = 1, nowr = 0;
  for (register size_t i = 1; i <= m; i++) {
    while (nowl < q[i].l) change(nowl++, -1);
    while (nowl > q[i].l) change(--nowl, 1);
    while (nowr > q[i].r) change(nowr--, -1);
    while (nowr < q[i].r) change(++nowr, 1);
    ans[q[i].num] = nowans;
  }
  for (register size_t i = 1; i <= m; i++) {
    write(*(ans + i));
    putchar('\n');
  }
  return 0;
}
