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 n, q;
int A[100050 + 10];
int ANS[100050 + 10];
int pre[100050 + 10];
int ind[100050 + 10];
int Query[100050 + 10][2];
int total[100050 + 10];
queue<int> pos[100050];
struct Bittree_plus {
  int A[100050 + 10];
  void add(int l, int r, int v) {
    A[l] += v;
    A[r + 1] -= v;
  }
  int sum(int x) {
    int ans = 0;
    for (int i = 1; i <= x; i++) {
      ans += A[i];
    }
    return ans;
  }
};
Bittree_plus bt;
bool cmp_r(int a, int b) { return Query[a][1] < Query[b][1]; }
int get();
int main() {
  int l, r, PRE_R = 0;
  n = get();
  q = get();
  for (int i = 1; i <= n; i++) {
    A[i] = get();
    if (A[i] > n)
      A[i] = 0;
    else
      total[A[i]]++;
    pre[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (total[A[i]] < A[i]) A[i] = 0, total[A[i]] = 0;
  }
  for (int i = 1; i <= q; i++) {
    Query[i][0] = get();
    Query[i][1] = get();
    ind[i] = i;
  }
  sort(ind + 1, ind + 1 + q, cmp_r);
  for (int k = 1; k <= q; k++) {
    int L = Query[ind[k]][0], R = Query[ind[k]][1];
    for (int i = PRE_R + 1; i <= R; i++) {
      int v = A[i];
      if (v == 0 || total[v] <= 0 || total[v] < v - pos[v].size()) continue;
      pos[v].push(i);
      total[v]--;
      if ((pos[v].size()) == v)
        bt.add(pre[v], pos[v].front(), +1);
      else if ((pos[v].size()) > v) {
        bt.add(pre[v], pos[v].front(), -1);
        pre[v] = pos[v].front() + 1;
        pos[v].pop();
        bt.add(pre[v], pos[v].front(), +1);
      }
    }
    ANS[ind[k]] = bt.sum(L);
    PRE_R = R;
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ANS[i]);
}
int get() {
  int f = 0, v = 0;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') break;
  if (ch == '-')
    f = 1;
  else
    v = ch - 48;
  while (isdigit(ch = getchar())) v = v * 10 + ch - 48;
  if (f == 1)
    return -v;
  else
    return v;
}
