#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
const long long INF = 1e9 + 5;
const long long mod = 1e9 + 7;
long long n, q, a[N], st[N], leftBound[N], res, ans[N];
vector<long long> endPoint[N];
void update(long long x, long long val) {
  for (x++; x <= n; x += x & -x) st[x] += val;
}
long long query(long long x) {
  long long res = 0;
  for (x++; x > 0; x -= x & -x) res += st[x];
  return res;
}
long long find(long long r, long long x) {
  long long l = 0;
  while (l != r) {
    long long m = (l + r) >> 1;
    if (query(m) <= res - x)
      l = m + 1;
    else
      r = m;
  }
  return l;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (long long i = 1; i <= q; i++) {
    long long l, r;
    cin >> l >> r;
    r = n - r;
    leftBound[i] = l;
    endPoint[r].push_back(i);
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      long long pos = find(i, a[i]);
      res++;
      update(pos, 1);
    }
    for (long long qu : endPoint[i]) ans[qu] = res - query(leftBound[qu]);
  }
  for (long long i = 1; i <= q; i++) cout << ans[i] << "\n";
}
