#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (true) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    long long p = b % a, q = a;
    a = p;
    b = q;
  }
}
long long powerMod(long long x, long long y) {
  long long res = 1;
  x %= 998244353;
  while (y > 0) {
    if (y & 1) res = (res * x) % 998244353;
    y = y >> 1;
    x = (x * x) % 998244353;
  }
  return res % 998244353;
}
vector<int> tree;
vector<int> a;
void upd(int idx, int v) {
  for (; idx < tree.size(); idx += (idx & (-idx))) {
    tree[idx] += v;
  }
}
void updr(int start, int end, int v) {
  upd(start, v);
  upd(end + 1, -v);
}
int query(int idx) {
  int sum = 0;
  for (; idx > 0; idx -= (idx & (-idx))) {
    sum += tree[idx];
  }
  return sum;
}
int get_max_left(int right) {
  int l = 1, m, answer = 0;
  int r = right;
  while (l <= r) {
    m = l + (r - l) / 2;
    if (query(m) >= a[right]) {
      answer = m;
      l = m + 1;
    } else
      r = m - 1;
  }
  return answer;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, q, i, j, k, l, p;
  cin >> n >> q;
  a.resize(n + 1);
  tree.resize(n + 2, 0);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  vector<vector<pair<int, int> > > queries(n + 1);
  for (i = 0; i < q; i++) {
    cin >> j >> k;
    k = n - k;
    queries[k].push_back({j + 1, i});
  }
  vector<int> answers(q);
  for (i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      l = get_max_left(i);
      if (l) updr(1, l, 1);
    }
    for (auto ii : queries[i]) {
      answers[ii.second] = query(ii.first);
    }
  }
  for (auto i : answers) {
    cout << i << "\n";
  }
  return 0;
}
