#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e17;
const long double pi = acos(-1.0);
const int maxn = 3e5 + 5;
int kase;
long long n, m;
int a[maxn], ans[maxn];
struct tree {
  int tr[maxn];
  void add(int x) {
    for (; x <= n; x += (x & -x)) tr[x]++;
  }
  int sum(int x) {
    int re = 0;
    for (; x; x -= (x & -x)) re += tr[x];
    return re;
  }
} tr;
vector<pair<int, int> > q[maxn];
void run() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (int i = 1, x, y; i <= m; i++) {
    cin >> x >> y;
    q[n - y].push_back({1 + x, i});
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      int l = 1, r = i, p = -1;
      while (l <= r) {
        int mid = l + r >> 1;
        if (tr.sum(i) - tr.sum(mid - 1) >= a[i])
          p = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (p != -1) tr.add(p);
    }
    for (auto j : q[i]) {
      ans[j.second] = tr.sum(i) - tr.sum(j.first - 1);
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  run();
  return 0;
}
