#include <bits/stdc++.h>
using namespace std;
class Fenwick {
  vector<int> x;
  int total;

 public:
  Fenwick(int n) {
    x = vector<int>(n + 1);
    total = 0;
  }
  int sum_to(size_t n) {
    int ans = 0;
    int i = 1;
    while (n > 0) {
      if (n & i) {
        ans += x[n];
        n -= (n & i);
      }
      i <<= 1;
    }
    return ans;
  }
  int sum_from(size_t n) { return total - sum_to(n); }
  void increment(int n) {
    int i = 1;
    while (n < x.size()) {
      if (n & i) {
        x[n]++;
        n += (n & i);
      }
      i <<= 1;
    }
    total += 1;
  }
  void print() {
    for (size_t i = 0; i < x.size(); i++) {
      cout << sum_from(i) << " ";
    }
    cout << endl;
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = i + 1 - a[i];
  }
  map<int, vector<pair<int, int>>> query;
  vector<int> ans(q);
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    query[n - y].push_back(pair<int, int>(i, x));
  }
  Fenwick weight(n);
  for (int i = 0; i < n; i++) {
    if (a[i] >= 0 && weight.sum_from(0) >= a[i]) {
      int upper = i + 1;
      int lower = 0;
      while (lower + 1 < upper) {
        int mid = (lower + upper) / 2;
        if (weight.sum_from(mid) >= a[i]) {
          lower = mid;
        } else {
          upper = mid;
        }
      }
      weight.increment(lower + 1);
    }
    for (pair<int, int> q : query[i + 1]) {
      ans[q.first] = weight.sum_from(q.second);
    }
  }
  for (int i : ans) {
    cout << i << "\n";
  }
}
