#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
int n, m, a[N], ans[N];
vector<pair<int, int> > q[N];
struct BIT {
  int tr[N];
  void init() { memset(tr, 0, sizeof(tr)); }
  void add(int x) {
    for (; x <= n; x += x & -x) tr[x]++;
  }
  int sum(int x) {
    int res = 0;
    for (; x; x -= x & -x) res += tr[x];
    return res;
  }
} bit;
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) read(a[i]), a[i] = i - a[i];
  int x, y;
  for (int i = 1; i <= m; ++i) {
    read(x), read(y);
    q[n - y].push_back({x + 1, i});
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= 0) {
      int l = 1, r = i, p = -1;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (bit.sum(i) - bit.sum(mid - 1) >= a[i])
          l = mid + 1, p = mid;
        else
          r = mid - 1;
      }
      if (~p) bit.add(p);
    }
    for (auto j : q[i]) {
      ans[j.second] = bit.sum(i) - bit.sum(j.first - 1);
    }
  }
  for (int i = 1; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}
