#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int M = N;
const int mod = 998244353;
int a[N], b[N], lft[N];
vector<int> ind[N];
long long int fen[N];
void add(long long int idx, long long int x, int n) {
  while (idx <= n) {
    fen[idx] += x;
    idx += idx & (-idx);
  }
}
long long int get(int idx) {
  long long int res = 0;
  while (idx > 0) {
    res += fen[idx];
    idx -= idx & (-idx);
  }
  return res;
}
void solve() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (int i = 1; i <= q; ++i) {
    int l, r;
    cin >> l >> r;
    l = 1 + l;
    r = n - r;
    lft[i] = l;
    ind[r].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= 0) {
      int l = 1, r = i, idx = -1;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (get(i) - get(mid - 1) >= a[i]) {
          idx = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      if (idx != -1) add(idx, 1, n);
    }
    for (int j = 0; j < ind[i].size(); ++j) {
      int idx = ind[i][j];
      b[idx] = get(i) - get(lft[idx] - 1);
    }
  }
  for (int i = 1; i <= q; ++i) cout << b[i] << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
