#include <bits/stdc++.h>
#pragma GCC optimize(2)
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 3e5 + 10;
int n, q;
int a[N];
struct zxs {
  int ls[N * 20];
  int rs[N * 20];
  int sum[N * 20];
  int root[N];
  int tot = 0;
  void insert(int &o, int pre, int l, int r, int val) {
    o = ++tot;
    sum[o] = sum[pre] + 1;
    ls[o] = ls[pre];
    rs[o] = rs[pre];
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (val <= mid)
      insert(ls[o], ls[pre], l, mid, val);
    else
      insert(rs[o], rs[pre], mid + 1, r, val);
  }
  int query(int o, int pre, int l, int r, int k) {
    if (l == r) return l;
    int mid = (l + r) >> 1;
    if (sum[rs[o]] - sum[rs[pre]] >= k)
      return query(rs[o], rs[pre], mid + 1, r, k);
    else
      return query(ls[o], ls[pre], l, mid, k - (sum[rs[o]] - sum[rs[pre]]));
  }
  int querysum(int o, int pre, int l, int r, int lf, int rt) {
    if (lf <= l && r <= rt) {
      return sum[o] - sum[pre];
    }
    int mid = (l + r) >> 1;
    int ans = 0;
    if (lf <= mid) ans = querysum(ls[o], ls[pre], l, mid, lf, rt);
    if (rt > mid) ans += querysum(rs[o], rs[pre], mid + 1, r, lf, rt);
    return ans;
  }
} T;
vector<pair<int, int> > vec[N];
int ans[N];
int lim[N];
int main() {
  n = read(), q = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    if (i < a[i]) {
      T.root[i] = T.root[i - 1];
      lim[i] = -1;
      continue;
    }
    a[i] = i - a[i];
    if (T.sum[T.root[i - 1]] < a[i]) {
      lim[i] = -1;
      T.root[i] = T.root[i - 1];
      continue;
    }
    if (a[i] == 0) {
      lim[i] = i - 1;
    } else
      lim[i] = T.query(T.root[i - 1], T.root[0], 0, n - 1, a[i]);
    T.insert(T.root[i], T.root[i - 1], 0, n - 1, lim[i]);
  }
  int x, y;
  for (int i = 1; i <= q; i++) {
    x = read(), y = read();
    vec[n - y].push_back({x, i});
  }
  for (int i = 1; i <= n; i++) {
    for (auto k : vec[i])
      ans[k.second] =
          T.querysum(T.root[i], T.root[0], 0, n - 1, k.first, n - 1);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
