#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::pair;
const int N = 3e5 + 1, INF = 0x3f3f3f3f;
int n, q, a[N], ans[N];
std::vector<pair<int, int> > Q[N];
namespace BIT {
int Sc[N];
void Add(int x, int d) {
  while (x <= n) {
    Sc[x] += d;
    x += x & -x;
  }
  return;
}
int Sum(int x) {
  int res = 0;
  while (x) {
    res += Sc[x];
    x -= x & -x;
  }
  return res;
}
}  // namespace BIT
int main() {
  std::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];
    if (a[i] < 0) a[i] = INF;
  }
  int x, y;
  for (int i = 1; i <= q; ++i) {
    cin >> x >> y;
    x++;
    y = n - y;
    Q[y].push_back(std::make_pair(x, i));
  }
  for (int i = 1; i <= n; ++i) {
    if (BIT::Sum(1) >= a[i]) {
      int L = 1, R = i, ans = 1;
      while (L <= R) {
        int mid = L + R >> 1;
        if (BIT::Sum(mid) >= a[i])
          ans = mid, L = mid + 1;
        else
          R = mid - 1;
      }
      BIT::Add(1, 1);
      BIT::Add(ans + 1, -1);
    }
    for (int j = 0; j < (int)Q[i].size(); ++j)
      ans[Q[i][j].second] = BIT::Sum(Q[i][j].first);
  }
  for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
  return 0;
}
