#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int INF = 0x3f3f3f3f;
long long ksm(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 3e5 + 10;
int n, q;
vector<pair<int, int> > op[N];
int tr[N], ans[N], a[N];
int lowbit(int x) { return x & -x; }
void add(int x, int k) {
  for (int i = x; i <= n; i += lowbit(i)) {
    tr[i] += k;
  }
}
int sum(int x) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) {
    res += tr[i];
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i] = i - a[i];
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l = l + 1, r = n - r;
    op[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      int l = 1, r = i, pos = 0;
      while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (sum(mid) >= a[i]) {
          l = mid;
          pos = mid;
        } else {
          r = mid - 1;
        }
      }
      if (sum(l) >= a[i]) pos = l;
      if (pos) {
        add(1, 1);
        add(pos + 1, -1);
      }
    }
    for (auto it : op[i]) {
      int l = it.first, id = it.second;
      ans[id] = sum(l);
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
