#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5;
struct FrogTree {
  int rt[MAXN + 5], sum[MAXN * 32], ls[MAXN * 32], rs[MAXN * 32], cnt;
  void ins(int& x, int y, int l, int r, int pos) {
    x = ++cnt;
    sum[x] = sum[y] + 1;
    ls[x] = ls[y];
    rs[x] = rs[y];
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
      ins(ls[x], ls[y], l, mid, pos);
    } else {
      ins(rs[x], rs[y], mid + 1, r, pos);
    }
  }
  int bs(int x, int l, int r, int b) {
    if (l == r) return l;
    int mid = (l + r) >> 1;
    if (sum[rs[x]] >= b) {
      return bs(rs[x], mid + 1, r, b);
    } else {
      return bs(ls[x], l, mid, b - sum[rs[x]]);
    }
  }
  int calc(int x, int l, int r, int ql, int qr) {
    if (!x) return 0;
    if (ql <= l && qr >= r) {
      return sum[x];
    }
    int mid = (l + r) >> 1;
    int tmp = 0;
    if (ql <= mid) tmp += calc(ls[x], l, mid, ql, qr);
    if (mid < qr) tmp += calc(rs[x], mid + 1, r, ql, qr);
    return tmp;
  }
  FrogTree() {
    rt[0] = 0;
    ls[0] = 0;
    rs[0] = 0;
  }
} FT;
int n, q, a[MAXN + 5], b[MAXN + 5], lim[MAXN + 5];
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (i < a[i]) {
      FT.rt[i] = FT.rt[i - 1];
      b[i] = -1;
      lim[i] = -1;
      continue;
    }
    b[i] = i - a[i];
    if (FT.sum[FT.rt[i - 1]] < b[i]) {
      lim[i] = -1;
      FT.rt[i] = FT.rt[i - 1];
      continue;
    }
    if (!b[i]) {
      lim[i] = i - 1;
    } else {
      lim[i] = FT.bs(FT.rt[i - 1], 0, n - 1, b[i]);
    }
    FT.ins(FT.rt[i], FT.rt[i - 1], 0, n - 1, lim[i]);
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    cout << FT.calc(FT.rt[n - y], 0, n - 1, x, n - 1) << endl;
  }
  return 0;
}
