#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn];
int bit[maxn];
int ans[maxn];
int query(int idx) {
  int ans = 0;
  for (int i = idx; i >= 1; i -= (i & -i)) {
    ans += bit[i];
  }
  return ans;
}
int n;
void update(int idx, int val) {
  if (idx <= 0) {
    return;
  }
  for (int i = idx; i <= n; i += (i & -i)) {
    bit[i] += val;
  }
}
int findLargestIdx(int target, int maksIdx) {
  int kiri = 1, kanan = maksIdx, mid, ans = -1;
  while (kiri <= kanan) {
    mid = (kiri + kanan) / 2;
    if ((query(maksIdx) - query(mid - 1)) >= target) {
      ans = mid;
      kiri = mid + 1;
    } else {
      kanan = mid - 1;
    }
  }
  return ans;
}
int main() {
  int q, i, j;
  scanf("%d %d", &n, &q);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i] = i - a[i];
  }
  vector<vector<int> > listKiri, listIdx;
  listKiri.assign(n + 1, vector<int>());
  listIdx.assign(n + 1, vector<int>());
  for (i = 1; i <= q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    int start = 1 + x, end = n - y;
    listKiri[end].push_back(start);
    listIdx[end].push_back(i);
  }
  for (int r = 1; r <= n; r++) {
    if (a[r] >= 0) {
      int largestIdx = findLargestIdx(a[r], r);
      update(largestIdx, 1);
    }
    for (i = 0; i < listKiri[r].size(); i++) {
      int kiri = listKiri[r][i];
      int idxQuery = listIdx[r][i];
      ans[idxQuery] = query(r) - query(kiri - 1);
    }
  }
  for (i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
};
