#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, q;
int a[N];
int answer[N];
vector<pair<int, int>> nothing[N];
struct fenw {
  int tree[N];
  void add(int x, int val) {
    for (int i = x; i <= n; i += (i & (-i))) {
      tree[i] += val;
    }
  }
  int get(int x) {
    int ans = 0;
    for (int i = x; i > 0; i -= (i & (-i))) {
      ans += tree[i];
    }
    return ans;
  }
} fenw;
void work() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
    if (a[i] < 0) a[i] = n + 1;
  }
  for (int i = 1; i <= q; i++) {
    int L, R;
    cin >> L >> R;
    nothing[n - R].push_back(make_pair(i, L + 1));
  }
  for (int i = 1; i <= n; i++) {
    int lo = 0, hi = i, res = 0;
    while (lo != hi) {
      int mid = (lo + hi + 1) >> 1;
      if (fenw.get(mid) >= a[i]) {
        res = mid;
        lo = mid;
      } else
        hi = mid - 1;
    }
    fenw.add(1, +1);
    fenw.add(lo + 1, -1);
    for (int j = 0; j < nothing[i].size(); j++) {
      answer[nothing[i][j].first] = fenw.get(nothing[i][j].second);
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << answer[i] << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  work();
  return 0;
}
