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 maxn = 1e5 + 100;
int a[maxn];
int num[maxn];
vector<int> pos[maxn];
struct Query {
  int l, r, id;
  Query(int a = 0, int b = 0, int c = 0) { l = a, r = b, id = c; }
  bool operator<(const Query &a) const { return r < a.r; }
};
struct node {
  int l, r, sum;
  int mid() { return (l + r) >> 1; }
};
struct segtree {
  node ns[maxn << 2];
  void pushup(int rt) {
    if (ns[rt].sum != 0) {
      ns[rt << 1].sum += ns[rt].sum;
      ns[rt << 1 | 1].sum += ns[rt].sum;
      ns[rt].sum = 0;
    }
  }
  void build(int rt, int l, int r) {
    ns[rt].l = l;
    ns[rt].r = r;
    ns[rt].sum = 0;
    if (l == r) return;
    build(rt << 1, l, ns[rt].mid());
    build(rt << 1 | 1, ns[rt].mid() + 1, r);
  }
  void update(int rt, int L, int R, int val) {
    int l = ns[rt].l, r = ns[rt].r;
    if (L <= l && r <= R) {
      ns[rt].sum += val;
    } else {
      pushup(rt);
      int mid = ns[rt].mid();
      if (L <= mid) update(rt << 1, L, R, val);
      if (mid < R) update(rt << 1 | 1, L, R, val);
    }
  }
  int query(int rt, int pos) {
    int l = ns[rt].l, r = ns[rt].r, mid = ns[rt].mid();
    if (l == r)
      return ns[rt].sum;
    else {
      pushup(rt);
      if (pos <= mid)
        return query(rt << 1, pos);
      else
        return query(rt << 1 | 1, pos);
    }
  }
} seg;
pair<int, int> len[maxn];
vector<Query> qu;
int ans[maxn];
int main() {
  int n, m;
  while (cin >> n >> m) {
    memset(num, 0, sizeof num);
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
      int t1, t2;
      cin >> t1 >> t2;
      qu.push_back(Query(t1, t2, i));
    }
    sort(qu.begin(), qu.end());
    seg.build(1, 1, n);
    int now = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] <= n) {
        int val = a[i];
        num[val]++;
        pos[val].push_back(i);
        if (num[val] == val) {
          len[val] = make_pair(1, pos[val][0]);
          seg.update(1, 1, pos[val][0], 1);
        } else if (num[val] > val) {
          seg.update(1, len[val].first, len[val].second, -1);
          len[val] = make_pair(len[val].second + 1, pos[val][num[val] - val]);
          seg.update(1, len[val].first, len[val].second, 1);
        }
        while (qu[now].r == i && now < m) {
          ans[qu[now].id] = seg.query(1, qu[now].l);
          now++;
        }
      }
    for (int i = 1; i <= m; i++) {
      cout << ans[i] << endl;
    }
  }
}
