#include <bits/stdc++.h>
using namespace std;
struct Query {
  int l, r, idx;
  bool operator<(const Query &o) const { return r < o.r; }
};
struct Seg {
  int node[1200008] = {
      0,
  };
  void update(int n, int l, int r, int s, int e) {
    if (r < s || e < l) return;
    if (s <= l && r <= e) {
      ++node[n];
      return;
    }
    int m = (l + r) >> 1;
    update(n + n, l, m, s, e);
    update(n + n + 1, m + 1, r, s, e);
  }
  int query(int n, int l, int r, int k) {
    if (l == r) return node[n];
    int m = (l + r) >> 1;
    if (k <= m) return query(n + n, l, m, k) + node[n];
    return query(n + n + 1, m + 1, r, k) + node[n];
  }
  int searchStart(int n, int cr, int k) {
    int l = 1, r = cr;
    while (l < r) {
      int m = (l + r) >> 1;
      if (query(1, 1, n, m) >= k)
        l = m + 1;
      else
        r = m;
    }
    return l - 1;
  }
} seg;
int n, q, a[300002], res[300002];
Query query[300002];
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[i] = i - a[i];
    if (a[i] < 0) a[i] = 1000000000;
  }
  for (int i = 0; i < q; ++i) {
    scanf("%d %d", &query[i].l, &query[i].r);
    query[i].l += 1;
    query[i].r = n - query[i].r;
    query[i].idx = i;
  }
  sort(query, query + q);
  int cr = 0;
  for (int i = 0; i < q; ++i) {
    int l = query[i].l;
    int r = query[i].r;
    while (cr < r) {
      ++cr;
      int cl = seg.searchStart(n, cr + 1, a[cr]);
      seg.update(1, 1, n, 1, cl);
    }
    res[query[i].idx] = seg.query(1, 1, n, query[i].l);
  }
  for (int i = 0; i < q; ++i) printf("%d\n", res[i]);
  return 0;
}
