#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
vector<int> ed[maxn];
int a[maxn], lft[maxn], ans[maxn];
int tree[maxn << 2], lazy[maxn << 2];
int n;
inline void pushup(int cur) { tree[cur] = tree[cur << 1] + tree[cur << 1 | 1]; }
inline void pushdown(int cur, int len) {
  if (lazy[cur]) {
    tree[cur << 1] += lazy[cur] * (len - (len >> 1));
    tree[cur << 1 | 1] += lazy[cur] * (len >> 1);
    lazy[cur << 1] += lazy[cur];
    lazy[cur << 1 | 1] += lazy[cur];
    lazy[cur] = 0;
  }
}
void update(int l, int r, int cur, int qr) {
  if (1 <= l && r <= qr) {
    ++lazy[cur];
    tree[cur] += r - l + 1;
    return;
  }
  pushdown(cur, r - l + 1);
  int mid = l + r >> 1;
  update(l, mid, cur << 1, qr);
  if (qr > mid) update(mid + 1, r, cur << 1 | 1, qr);
  pushup(cur);
}
int query(int l, int r, int cur, int pos) {
  if (l == r) return tree[cur];
  pushdown(cur, r - l + 1);
  int mid = l + r >> 1;
  if (pos <= mid)
    return query(l, mid, cur << 1, pos);
  else
    return query(mid + 1, r, cur << 1 | 1, pos);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) cin >> a[i], a[i] = i - a[i];
  for (int i = 1; i <= q; ++i) {
    int a, b;
    cin >> a >> b;
    ed[n - b].push_back(i);
    lft[i] = a + 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= 0) {
      int l = 1, r = i, mid, res = -1;
      while (l <= r) {
        mid = l + r >> 1;
        if (query(1, n, 1, mid) >= a[i])
          res = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (res != -1) update(1, n, 1, res);
    }
    for (int id : ed[i]) ans[id] = query(1, n, 1, lft[id]);
  }
  for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
  return 0;
}
