#include <bits/stdc++.h>
using namespace std;
int n, q, a[300010], BIT[300010], res[300010];
vector<pair<int, int> > query[300010];
void upl(int x, int val) {
  for (; x <= n; x += (-x & x)) BIT[x] += val;
}
int dwl(int x) {
  int tmp = 0;
  for (; x > 0; x -= (-x & x)) tmp += BIT[x];
  return tmp;
}
void readf() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (int i = 1; i <= q; ++i) {
    int l, r;
    cin >> l >> r;
    query[n - r].emplace_back(l + 1, i);
  }
}
void solve() {
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= 0) {
      int l = 1;
      int r = i;
      int pos = 0;
      while (l <= r) {
        int mid = l + r >> 1;
        if (dwl(mid) >= a[i]) {
          pos = mid;
          l = mid + 1;
        } else
          r = mid - 1;
      }
      upl(1, 1);
      upl(pos + 1, -1);
    }
    for (auto v : query[i]) res[v.second] = dwl(v.first);
  }
  for (int i = 1; i <= q; ++i) cout << res[i] << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  readf();
  solve();
}
