#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
using namespace std;
const long long md = 1e9 + 7;
const long long N = 1100000;
const long long inf = 1e18;
vector<long long> t;
long long n;
long long sum(long long i) {
  long long r = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) r += t[i];
  return r;
}
void inc(long long i, long long a) {
  for (; i < n; i = (i | (i + 1))) t[i] += a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  long long q, k, l, j, w;
  cin >> n >> q;
  vector<long long> a(n), R(q);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = i + 1 - a[i];
  }
  vector<pair<pair<long long, long long>, long long>> b;
  for (int i = 0; i < q; i++) {
    cin >> k >> l;
    b.push_back({{n - l - 1, k}, i});
  }
  sort(b.begin(), b.end());
  ;
  j = 0;
  t.assign(n, 0);
  for (int i = 0; i < n; i++) {
    if (a[i] >= 0) {
      long long mi = -1, ma = i + 1;
      while (ma > mi + 1) {
        w = (ma + mi) / 2;
        if (sum(w) >= a[i])
          mi = w;
        else
          ma = w;
      }
      inc(0, 1);
      inc(mi + 1, -1);
    }
    while (j < q && b[j].first.first == i) {
      R[b[j].second] = sum(b[j].first.second);
      j++;
    }
  }
  for (int i = 0; i < q; i++) cout << R[i] << '\n';
}
