#include <bits/stdc++.h>
using namespace std;
int lg(long long n) {
  assert(n > 0);
  int ans = -1;
  while (n) {
    ans++;
    n >>= 1;
  }
  return ans;
}
struct Fenwick {
  int n;
  vector<int> bit;
  Fenwick(int s) {
    n = s;
    bit.assign(s + 1, 0);
  }
  int lb(int x) { return x & (-x); }
  void add(int pos, int val) {
    for (int i = pos; i <= n; i += lb(i)) {
      bit[i] += val;
    }
  }
  int query(int pos) {
    int ans = 0;
    for (int i = pos; i > 0; i -= lb(i)) {
      ans += bit[i];
    }
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n + 1), ans(q);
  vector<vector<pair<int, int>>> endhere(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
    if (a[i] < 0) a[i] = 1e9;
  }
  Fenwick bit(n);
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    endhere[n - r].push_back(make_pair(i, l + 1));
  }
  for (int r = 1; r <= n; r++) {
    int pl = 0, pr = r;
    while (pl < pr) {
      int m = (pl + pr) / 2 + 1;
      if (bit.query(m) >= a[r])
        pl = m;
      else
        pr = m - 1;
    }
    bit.add(1, 1);
    bit.add(pl + 1, -1);
    for (pair<int, int> p : endhere[r]) {
      int idx = p.first;
      int l = p.second;
      ans[idx] = bit.query(l);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
