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 = 100001;
int sum[MAXN << 2], col[MAXN << 2], pre[MAXN], n, m, a[MAXN];
void build(int l, int r, int rt) {
  sum[rt] = col[rt] = 0;
  if (l == r) return;
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
void PushUp(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
void PushDown(int rt) {
  if (col[rt] != 0) {
    col[rt << 1] += col[rt];
    col[rt << 1 | 1] += col[rt];
    sum[rt << 1] += col[rt];
    sum[rt << 1 | 1] += col[rt];
    col[rt] = 0;
  }
}
int query(int x, int l, int r, int rt) {
  if (l == r) return sum[rt];
  PushDown(rt);
  int m = (l + r) >> 1;
  if (x <= m)
    return query(x, l, m, rt << 1);
  else
    return query(x, m + 1, r, rt << 1 | 1);
}
void update(int L, int R, int c, int l, int r, int rt) {
  if (L <= l && r <= R) {
    sum[rt] += c;
    col[rt] += c;
    return;
  }
  PushDown(rt);
  int m = (l + r) >> 1;
  if (L <= m) update(L, R, c, l, m, rt << 1);
  if (m < R) update(L, R, c, m + 1, r, rt << 1 | 1);
  PushUp(rt);
}
struct node {
  int x, y, id;
  node(int x = 0, int y = 0, int id = 0) : x(x), y(y), id(id) {}
  bool operator<(const node& b) const { return this->y < b.y; }
} q[MAXN];
void input() {
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &q[i].x, &q[i].y);
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
  build(1, n, 1);
  for (int i = 1; i <= n; ++i) pre[i] = 1;
}
int cnt[MAXN], query_ans[MAXN];
vector<int> g[MAXN];
void solve() {
  memset(cnt, 0, sizeof(cnt));
  memset(query_ans, 0, sizeof(query_ans));
  for (int i = 1; i <= n; ++i) {
    g[i].clear();
    g[i].push_back(0);
  }
  int cnt_query = 1;
  for (int i = 1; i <= n; ++i) {
    int val = a[i];
    if (val >= MAXN) continue;
    ++cnt[val];
    g[val].push_back(i);
    if (cnt[val] == val)
      update(1, g[val][1], 1, 1, n, 1);
    else if (cnt[val] > val) {
      int l = g[val][cnt[val] - val - 1] + 1, r = g[val][cnt[val] - val];
      update(l, r, -1, 1, n, 1);
      l = g[val][cnt[val] - val] + 1;
      r = g[val][cnt[val] - val + 1];
      update(l, r, 1, 1, n, 1);
    }
    while (q[cnt_query].y == i) {
      query_ans[q[cnt_query].id] = query(q[cnt_query].x, 1, n, 1);
      ++cnt_query;
      if (cnt_query > m) break;
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", query_ans[i]);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    input();
    solve();
  }
  return 0;
}
