#include <bits/stdc++.h>
using namespace std;
const long long N = 3 * 1e5 + 5;
long long n, q;
vector<pair<long long, long long>> query[N];
struct BIT {
  long long arr[N];
  void update(long long i, long long x) {
    while (i <= n) {
      arr[i] += x;
      i += i & -i;
    }
  }
  long long get(long long i) {
    long long ans = 0;
    while (i >= 1) {
      ans += arr[i];
      i -= i & -i;
    }
    return ans;
  }
} bit;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  vector<long long> a(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
    if (a[i] < 0) {
      a[i] = 1e9;
    }
  }
  for (long long i = 1; i <= q; i++) {
    long long x, y;
    cin >> x >> y;
    x = x + 1;
    y = n - y;
    query[y].push_back({x, i});
  }
  vector<long long> ans(q + 1);
  for (long long r = 1; r <= n; r++) {
    long long left = 0, right = r + 1;
    while (left + 1 < right) {
      long long mid = left + (right - left) / 2;
      if (bit.get(mid) >= a[r]) {
        left = mid;
      } else {
        right = mid;
      }
    }
    if (left != 0) {
      bit.update(1, 1);
      bit.update(left + 1, -1);
    }
    for (auto p : query[r]) {
      ans[p.second] = bit.get(p.first);
    }
  }
  for (long long i = 1; i <= q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
