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;
const int N = 400000 + 10;
vector<int> Pos[N];
int n, q, ans[N], data[N], p[N], last[N];
struct Query {
  int L, R, id;
  bool operator<(const Query& rhs) const { return R < rhs.R; }
} Q[N];
struct SegmentTree {
  int sum[N], addv[N], _sum, val, y1, y2;
  void maintain(int L, int R, int o) {
    sum[o] = 0;
    if (R > L) sum[o] = sum[o * 2] + sum[o * 2 + 1];
    sum[o] += addv[o] * (R - L + 1);
  }
  void update(int L, int R, int o) {
    if (y1 <= L && R <= y2) {
      addv[o] += val;
    } else {
      int M = (L + R) >> 1;
      if (y1 <= M) update(L, M, o * 2);
      if (y2 > M) update(M + 1, R, o * 2 + 1);
    }
    maintain(L, R, o);
  }
  void query(int L, int R, int o, int add) {
    if (y1 <= L && R <= y2) {
      _sum += sum[o] + add * (R - L + 1);
    } else {
      int M = (L + R) >> 1;
      if (y1 <= M) query(L, M, o * 2, add + addv[o]);
      if (y2 > M) query(M + 1, R, o * 2 + 1, add + addv[o]);
    }
  }
} Seg;
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &data[i]);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &Q[i].L, &Q[i].R);
    Q[i].id = i;
  }
  sort(Q + 1, Q + 1 + q);
  int now = 1;
  for (int i = 1; i <= n; i++) {
    if (data[i] <= n) {
      Pos[data[i]].push_back(i);
      if (Pos[data[i]].size() == data[i]) {
        Seg.y1 = 1;
        Seg.y2 = Pos[data[i]][0];
        Seg.val = 1;
        Seg.update(1, n, 1);
        last[data[i]] = 1;
      }
      if (Pos[data[i]].size() > data[i]) {
        Seg.y1 = last[data[i]];
        Seg.y2 = Pos[data[i]][p[data[i]]];
        Seg.val = -1;
        Seg.update(1, n, 1);
        Seg.y1 = Pos[data[i]][p[data[i]]++] + 1;
        last[data[i]] = Seg.y1;
        Seg.y2 = Pos[data[i]][p[data[i]]];
        Seg.val = 1;
        Seg.update(1, n, 1);
      }
    }
    while (Q[now].R == i) {
      Seg._sum = 0;
      Seg.y1 = Seg.y2 = Q[now].L;
      Seg.query(1, n, 1, 0);
      ans[Q[now++].id] = Seg._sum;
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
