#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
int n, q;
int a[300005];
int ans[300005];
vector<pair<int, int> > e[300005];
int f[300005];
void add(int i, int x) {
  for (; i <= n; i += i & -i) {
    f[i] += x;
  }
}
int get(int i) {
  int v = 0;
  for (; i > 0; i -= i & -i) {
    v += f[i];
  }
  return v;
}
int get_idx(int x, int bd) {
  int l = 0, r = bd + 1, m;
  while (r - l > 1) {
    m = (l + r) >> 1;
    if (get(m) >= x) {
      l = m;
    } else {
      r = m;
    }
  }
  return l;
}
int main() {
  ios::sync_with_stdio(false);
  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, x, y; i <= q; ++i) {
    cin >> x >> y;
    e[n - y].push_back({i, x + 1});
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= 0) {
      int idx = get_idx(a[i], i);
      add(1, 1), add(idx + 1, -1);
      ++cnt;
    }
    for (auto x : e[i]) {
      ans[x.first] = get(x.second);
    }
  }
  for (int i = 1; i <= q; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
