#include <bits/stdc++.h>
using namespace std;
struct Fenwick {
  vector<long long> BIT;
  long long N;
  Fenwick(long long n) {
    N = n + 2;
    BIT.resize(N + 10);
  }
  void reset() {
    for (long long i = 0; i <= N; i++) {
      BIT[i] = 0;
    }
  }
  void add(long long r, long long value) {
    for (long long i = r; i <= N; i = i | (i + 1)) {
      BIT[i] += value;
    }
  }
  long long qry(long long r) {
    long long ans = 0;
    for (long long i = r; i >= 0; i = (i & (i + 1)) - 1) {
      ans += BIT[i];
    }
    return ans;
  }
};
void solve() {
  long long n, q;
  cin >> n >> q;
  vector<long long> v(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
    v[i] = i - v[i];
  }
  42;
  vector<vector<tuple<long long, long long>>> queries(n + 1);
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    queries[n - r].push_back({l + 1, i});
  }
  vector<long long> ans(q);
  Fenwick sg(n + 2);
  for (long long i = 1; i <= n; i++) {
    if (v[i] >= 0) {
      long long l = 1, h = i;
      long long cur = 0;
      while (l <= h) {
        long long m = l + (h - l) / 2;
        if (sg.qry(m) >= v[i]) {
          cur = m;
          l = m + 1;
        } else {
          h = m - 1;
        }
      }
      sg.add(1, 1);
      sg.add(cur + 1, -1);
    }
    for (auto j : queries[i]) {
      ans[get<1>(j)] = sg.qry(get<0>(j));
    }
  }
  for (auto i : ans) {
    cout << i << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
