#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long int gcd(long long int A, long long int B) {
  if (!B) return A;
  return gcd(B, A % B);
}
vector<vector<pair<int, int>>> r(300005);
struct fenwick {
  long long int n;
  vector<long long int> bit;
  void upd(long long int pos, long long int val) {
    for (int i = pos; i <= n; i += i & (-i)) bit[i] += val;
  }
  long long int query(long long int r) {
    long long int res = 0;
    for (int i = r; i > 0; i -= i & (-i)) res += bit[i];
    return res;
  }
  void init(vector<long long int> a) {
    for (int i = 1; i <= n; i++) {
      bit[i] += a[i];
      int j = i + (i & (-i));
      if (j <= n) bit[j] += bit[i];
    }
  }
  int search(long long int val) {
    long long int sum = 0, pos = 0;
    for (int i = 19; i >= 0; i--) {
      if (pos + (1 << i) < n && sum + bit[pos + (1 << i)] < val) {
        pos += (1 << i);
        sum += bit[pos];
      }
    }
    return pos + 1;
  }
  fenwick(int _n) {
    n = _n;
    bit.resize(n + 1);
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  fenwick f(n + 1);
  vector<long long int> a(n + 1);
  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 = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    r[n - y].push_back({x + 1, i});
  }
  vector<long long int> ans(q);
  for (int i = 1; i <= n; i++) {
    int s = 1, e = i;
    while (e >= s) {
      int m = (s + e) / 2;
      if (f.query(m) >= a[i])
        s = m + 1;
      else
        e = m - 1;
    }
    f.upd(1, 1);
    f.upd(e + 1, -1);
    for (auto x : r[i]) {
      ans[x.second] = f.query(x.first);
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
}
