#include <bits/stdc++.h>
using namespace std;
void fen_update(vector<int> &tree, int i, int delta) {
  for (; i < tree.size(); i |= i + 1) tree[i] += delta;
}
int fen_get(const vector<int> &tree, int i) {
  int sum = 0;
  for (; i > 0; i &= i - 1) sum += tree[i - 1];
  return sum;
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i], a[i] = i - a[i] + 1;
  vector<vector<pair<int, int>>> z(n + 1);
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    z[n - y - 1].push_back({x, i});
  }
  vector<int> t(n), ans(q);
  for (int i = 0; i < n; i++) {
    if (a[i] >= 0) {
      int l = 0, r = i + 1;
      while (l < r) {
        int m = (l + r) >> 1;
        int v = fen_get(t, i + 1) - fen_get(t, m);
        if (v >= a[i])
          l = m + 1;
        else
          r = m;
      }
      fen_update(t, l - 1, 1);
    }
    for (auto p : z[i]) ans[p.second] = fen_get(t, i + 1) - fen_get(t, p.first);
  }
  for (auto x : ans) cout << x << endl;
  return 0;
}
