#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int c[N], n;
int lowbit(int x) { return x & (-x); }
void add(int x, int val) {
  while (x <= n) {
    c[x] += val;
    x += lowbit(x);
  }
}
int sum(int x) {
  int ans = 0;
  while (x) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
vector<pair<int, int> > q[N];
int a[N], ans[N];
int main() {
  int x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (int i = 1; i <= x; i++) {
    int l, r;
    cin >> l >> r;
    l = l + 1;
    r = n - r;
    q[r].push_back(make_pair(l, i));
  }
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      int l = 1, r = i;
      int pos = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (sum(mid) >= a[i]) {
          l = mid + 1;
          pos = mid;
        } else
          r = mid - 1;
      }
      if (pos) {
        add(1, 1);
        add(pos + 1, -1);
      }
    }
    for (int j = 0; j < q[i].size(); j++) {
      int l = q[i][j].first;
      int id = q[i][j].second;
      ans[id] = sum(l);
    }
  }
  for (int i = 1; i <= x; i++) {
    cout << ans[i] << endl;
  }
}
