#include <bits/stdc++.h>
using namespace std;
int n, q, a[300001], ans[300001], bit[300001];
vector<pair<int, int> > que[300001];
void add(int pos, int v) {
  for (int i = pos; i <= n; i += (i & -i)) bit[i] += v;
}
int query(int pos) {
  int ret = 0;
  for (int i = pos; i; i -= (i & -i)) ret += bit[i];
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (int i = 1, a, b; i <= q; i++) {
    cin >> a >> b;
    que[n - b].push_back({a + 1, i});
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      int l = 0, r = i + 1;
      while (l + 1 < r) {
        int mid = (l + r) >> 1;
        if (query(mid) >= a[i])
          l = mid;
        else
          r = mid;
      }
      add(1, 1);
      add(l + 1, -1);
    }
    for (auto p : que[i]) ans[p.second] = query(p.first);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
  return 0;
}
