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;
int a[100010];
map<int, int> mp;
vector<int> g[100010];
int poss[100010];
int val[100010], add[100010], ans[100010];
struct Quest {
  int l, r, id;
};
bool cmp(const Quest &a, const Quest &b) { return a.l < b.l; }
Quest q[100010];
int tt[100010];
void update(int x, int val) {
  while (x < 100010) {
    tt[x] += val;
    x += x & -x;
  }
}
int read(int x) {
  int ans = 0;
  while (x > 0) {
    ans += tt[x];
    x -= x & -x;
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  mp.clear();
  int now = 0;
  for (int i = 0; i <= 100000; i++) g[i].clear();
  memset(val, 0, sizeof(val));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (mp.find(a[i]) == mp.end()) mp[a[i]] = now++;
    val[mp[a[i]]] = a[i];
    g[mp[a[i]]].push_back(i);
    poss[i] = g[mp[a[i]]].size() - 1;
  }
  memset(tt, 0, sizeof(tt));
  for (int i = 0; i < now; i++) {
    int x = val[i], len = g[i].size();
    if (x == 0) continue;
    if (x - 1 >= len) continue;
    int rr;
    rr = g[i][x - 1];
    int trr;
    if (x >= len)
      trr = n + 1;
    else
      trr = g[i][x];
    update(rr, 1);
    update(trr, -1);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q, q + m, cmp);
  int pos = 1;
  for (int i = 0; i < m; i++) {
    while (pos < q[i].l) {
      int tid = poss[pos];
      int hh = mp[a[pos]];
      if (tid + a[pos] - 1 < g[hh].size()) {
        int rr = g[hh][tid + a[pos] - 1], trr;
        if (tid + a[pos] < g[hh].size())
          trr = g[hh][tid + a[pos]];
        else
          trr = n + 1;
        update(rr, -1);
        update(trr, 1);
        if (trr != n + 1) {
          int trr2;
          if (tid + a[pos] + 1 < g[hh].size())
            trr2 = g[hh][tid + a[pos] + 1];
          else
            trr2 = n + 1;
          update(trr, 1);
          update(trr2, -1);
        }
      }
      pos++;
    }
    ans[q[i].id] = read(q[i].r);
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
