#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
long long n, m;
long long tr[N];
long long a[N], ans[N];
map<long long, vector<pair<long long, long long>>> mp;
map<long long, long long> mp1;
void add(long long x, long long k) {
  for (; x <= n; x += -x & x) tr[x] += k;
}
long long ask(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += tr[x];
  return ans;
}
signed main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (long long i = 1; i <= n; i++) {
    long long k;
    scanf("%lld", &k);
    if (i - k < 0)
      a[i] = n + 1;
    else
      a[i] = i - k;
  }
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    mp[n - y].push_back({x + 1, i});
    mp1[n - y] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    long long l = 0, r = i;
    while (l < r) {
      long long mid = (l + r + 1) >> 1;
      if (ask(mid) >= a[i])
        l = mid;
      else
        r = mid - 1;
    }
    add(1, 1);
    add(l + 1, -1);
    if (mp1[i])
      for (long long j = 0; j <= mp[i].size() - 1; j++)
        ans[mp[i][j].second] = ask(mp[i][j].first);
  }
  for (long long i = 1; i <= m; i++) cout << ans[i] << endl;
  return 0;
}
