#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
const int maxn = 3e5 + 1009;
int n, m, q, ans[maxn], a[maxn], t[maxn];
vector<int> Get[maxn], id[maxn];
void read() {}
template <typename T, typename... T2>
inline void read(T &x, T2 &...oth) {
  x = 0;
  int ch = getchar(), f = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  if (f) x = -x;
  read(oth...);
}
void add(int x, int f) {
  for (; x <= n; x += x & -x) t[x] += f;
}
int query(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += t[x];
  return ans;
}
signed main(signed argc, char const *argv[]) {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] = i - x;
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    l++;
    r = n - r;
    Get[r].push_back(l);
    id[r].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0) {
      int l = 1, r = i - 1;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (query(mid) < a[i])
          r = mid - 1;
        else
          l = mid + 1;
      }
      if (r >= 1) {
        add(1, 1);
        add(r + 1, -1);
      }
    }
    if (!a[i]) add(1, 1), add(i + 1, -1);
    for (int j = 0; j < Get[i].size(); j++) ans[id[i][j]] = query(Get[i][j]);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
