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>
#pragma comment(linker, "/stack:102400000,102400000")
using namespace std;
const int N = 100005;
const int M = 500005;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const double Pi = acos(-1.0);
int lowbit(int x) { return x & (-x); }
template <class T>
inline T f_min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T f_max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T f_abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T f_gcd(T a, T b) {
  return b == 0 ? a : f_gcd(b, a % b);
}
template <class T>
inline T f_Lcm(T a, T b) {
  return a / f_gcd(a, b) * b;
}
template <class T>
inline void f_swap(T &a, T &b) {
  T t = a;
  a = b;
  b = t;
}
bool is_digit(char a) {
  if (a >= '0' && a <= '9') return true;
  return false;
}
bool is_lowch(char a) {
  if (a >= 'a' && a <= 'z') return true;
  return false;
}
bool is_upch(char a) {
  if (a >= 'A' && a <= 'Z') return true;
  return false;
}
int a[N];
struct Node {
  int x, y, id;
  Node() {}
  Node(int _x, int _y, int _id) : x(_x), y(_y), id(_id) {}
  bool operator<(const Node &ah) const { return x < ah.x; }
} q[N];
vector<Node> vec[N];
int id[N], num[N];
struct p {
  int x, x2, y2, op;
  bool operator<(const p &ah) const {
    if (x != ah.x) return x < ah.x;
    return op < ah.op;
  }
} b[N << 2];
int sum[N << 2], add[N << 2];
inline void push_down(int i) {
  if (add[i]) {
    add[(i << 1)] += add[i];
    add[(i << 1 | 1)] += add[i];
    sum[(i << 1)] += add[i];
    sum[(i << 1 | 1)] += add[i];
    add[i] = 0;
  }
}
inline void update(int i, int l, int r, int L, int R, int val) {
  if (l == L && r == R) {
    sum[i] += val;
    add[i] += val;
    return;
  }
  push_down(i);
  int mid = L + R >> 1;
  if (r <= mid)
    update((i << 1), l, r, L, mid, val);
  else if (l > mid)
    update((i << 1 | 1), l, r, mid + 1, R, val);
  else
    update((i << 1), l, mid, L, mid, val),
        update((i << 1 | 1), mid + 1, r, mid + 1, R, val);
}
inline int query(int i, int x, int L, int R) {
  if (L == R) return sum[i];
  push_down(i);
  int mid = L + R >> 1;
  if (x <= mid)
    return query((i << 1), x, L, mid);
  else
    return query((i << 1 | 1), x, mid + 1, R);
}
int ans[N];
void print(int i, int L, int R) {
  printf("[%d,%d] : sum = %d, add = %d\n", L, R, sum[i], add[i]);
  if (L == R) return;
  int mid = L + R >> 1;
  print((i << 1), L, mid);
  print((i << 1 | 1), mid + 1, R);
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    memset(id, 0, sizeof(id));
    memset(num, 0, sizeof(num));
    for (int i = 1; i <= n; ++i) vec[i].clear();
    for (int i = 1; i <= n; ++i) {
      if (a[i] > n) continue;
      num[a[i]]++;
      vec[a[i]].push_back(Node(id[a[i]] + 1, i, 0));
      id[a[i]] = i;
    }
    for (int i = 1; i <= n; ++i) id[i] = n + 1;
    int cnt = 0;
    for (int i = n; i > 0; --i) {
      if (a[i] > n) continue;
      if (num[a[i]] >= a[i]) {
        b[cnt].x = vec[a[i]][num[a[i]] - a[i]].x;
        b[cnt].x2 = i;
        b[cnt].y2 = id[a[i]] - 1;
        b[cnt++].op = 0;
        b[cnt].x = vec[a[i]][num[a[i]] - a[i]].y;
        b[cnt].x2 = i;
        b[cnt].y2 = id[a[i]] - 1;
        b[cnt++].op = 1;
        num[a[i]]--;
      }
      id[a[i]] = i;
    }
    sort(b, b + cnt);
    for (int i = 0; i < m; ++i) scanf("%d%d", &q[i].x, &q[i].y), q[i].id = i;
    sort(q, q + m);
    memset(sum, 0, sizeof(sum));
    memset(add, 0, sizeof(add));
    int x = 0;
    for (int i = 0; i < m; ++i) {
      for (; x < cnt && (b[x].x < q[i].x || (b[x].x == q[i].x && b[x].op == 0));
           ++x) {
        if (b[x].op == 0)
          update(1, b[x].x2, b[x].y2, 1, n, 1);
        else
          update(1, b[x].x2, b[x].y2, 1, n, -1);
      }
      ans[q[i].id] = query(1, q[i].y, 1, n);
    }
    for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
  }
  return 0;
}
