#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  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, M = 1e6 + 10;
int n, q;
int a[N];
int tr[N];
vector<pair<int, int> > query[N];
int ans[N];
int lowbit(const int& x) { return x & -x; }
void add(const int& x, const int& d) {
  for (int i = x; i <= n + 1; i += lowbit(i)) tr[i] += d;
}
int sum(const int& x) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) res += tr[i];
  return res;
}
int getPos(const int& x, int l, int r) {
  if (r < l) return -1;
  while (l < r) {
    int mid = l + r + 1 >> 1;
    if (sum(mid) >= x)
      l = mid;
    else
      r = mid - 1;
  }
  if (sum(l) < x) return -1;
  return l;
}
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 = 0; i < q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x++;
    y = n - y;
    query[y].push_back({x, i});
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      int pos = getPos(a[i], 1, i);
      if (pos != -1) {
        add(1, 1);
        add(pos + 1, -1);
      }
    }
    for (int j = 0; j < query[i].size(); j++) {
      ans[query[i][j].second] = sum(query[i][j].first);
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}
