#include <bits/stdc++.h>
using namespace std;
int a[300005], tree[300005], ans[300005];
vector<pair<int, int>> p[300005];
void add(int x, int k) {
  while (x <= 300000) {
    tree[x] += k;
    x += x & (-x);
  }
}
int query(int x) {
  int res = 0;
  while (x) {
    res += tree[x];
    x -= x & (-x);
  }
  return res;
}
int main() {
  int n, q;
  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 x, y;
    cin >> x >> y;
    p[n - y].push_back({x + 1, i});
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0 && query(1) >= a[i]) {
      int l = 1, r = i;
      while (r >= l) {
        int mid = (l + r) / 2;
        if (query(mid) >= a[i])
          l = mid + 1;
        else
          r = mid - 1;
      }
      add(1, 1);
      add(l, -1);
    }
    for (auto j : p[i]) {
      ans[j.second] = query(j.first);
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << endl;
  }
}
