#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
mt19937 rnd(time(0));
const int MAXN = 1200007;
int t[MAXN], is[MAXN];
void push(int v, int vl, int vr) {
  t[v] += (vr - vl + 1) * is[v];
  if (vl != vr) {
    is[v + v] += is[v];
    is[v + v + 1] += is[v];
  }
  is[v] = 0;
}
void update(int v, int vl, int vr, int l, int r, int val) {
  push(v, vl, vr);
  if (vl > r || l > vr) {
    return;
  }
  if (vl >= l && vr <= r) {
    is[v] += val;
    push(v, vl, vr);
    return;
  }
  int mid = (vl + vr) >> 1;
  update(v + v, vl, mid, l, r, val);
  update(v + v + 1, mid + 1, vr, l, r, val);
  t[v] = t[v + v] + t[v + v + 1];
}
int get(int v, int vl, int vr, int pos) {
  push(v, vl, vr);
  if (vl == vr) {
    return t[v];
  }
  int mid = (vl + vr) >> 1;
  if (pos <= mid) {
    return get(v + v, vl, mid, pos);
  } else {
    return get(v + v + 1, mid + 1, vr, pos);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  VI a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
    a[i] = i - a[i];
    if (a[i] < 0) {
      a[i] = 1e9;
    }
  }
  vector<vector<PII>> queries(n);
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    queries[n - r - 1].emplace_back(l, i);
  }
  VI ans(n);
  for (int r = 0; r < n; ++r) {
    int L = 0, R = r, pos = -1;
    while (L <= R) {
      int mid = (L + R) >> 1;
      if (get(1, 0, n - 1, mid) >= a[r]) {
        L = mid + 1;
        pos = mid;
      } else {
        R = mid - 1;
      }
    }
    update(1, 0, n - 1, 0, pos, 1);
    for (auto [l, id] : queries[r]) {
      ans[id] = get(1, 0, n - 1, l);
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
