#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  for (char& c : s) c = c == ',' ? ' ' : c;
  stringstream ss;
  ss << s;
  vector<string> res;
  for (string z; ss >> z; res.push_back(z))
    ;
  return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
  if (idx > 0) cerr << ", ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, T...);
}
void localTest() {}
const long long N = 3e5 + 5;
long long BIT[N], A[N], ans[N];
void update(long long idx, long long val) {
  for (; idx < N; idx += (idx & -idx)) {
    BIT[idx] += val;
  }
  return;
}
long long query(long long idx) {
  long long ret = 0;
  for (; idx > 0; idx -= (idx & -idx)) {
    ret += BIT[idx];
  }
  return ret;
}
vector<pair<long long, long long> > Q[N];
int main() {
  localTest();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q;
  cin >> n >> q;
  vector<long long> ele;
  for (long long i = 1; i <= n; ++i) {
    cin >> A[i];
    A[i] = i - A[i];
  }
  for (long long i = 1; i <= q; ++i) {
    long long x, y, l, r;
    cin >> x >> y;
    l = x + 1;
    r = n - y;
    Q[r].push_back({l, i});
  }
  for (long long i = 1; i <= n; ++i) {
    long long lo = 1, hi = i;
    if (A[i] >= 0) {
      long long idx = 0;
      while (lo <= hi) {
        long long mid = (lo + hi) >> 1;
        if (query(mid) >= A[i]) {
          idx = mid;
          lo = mid + 1;
        } else {
          hi = mid - 1;
        }
      }
      if (idx) {
        update(1, 1);
        update(idx + 1, -1);
      }
    }
    for (auto u : Q[i]) {
      ans[u.second] = query(u.first);
    }
  }
  for (long long i = 1; i <= q; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
