#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
const int MAXM = 2e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
long long N, M, K;
long long a[MAXN];
int cnt0[MAXN];
long long bit[MAXN];
int ans[MAXN];
int lowbit(int x) { return x & (-x); }
void updata(int x, int val) {
  while (x <= N) {
    bit[x] += val;
    x += lowbit(x);
  }
}
long long sum(int x) {
  long long ans = 0;
  while (x) {
    ans += bit[x];
    x -= lowbit(x);
  }
  return ans;
}
struct quest {
  long long l, r, id;
} ask[MAXN];
int cmp1(quest a, quest b) { return a.r < b.r; }
void init() { cnt0[0] = 0; }
void solve() {
  int pos;
  int l, r, m;
  N = read();
  M = read();
  for (int i = 1; i <= N; i++) {
    a[i] = i - read();
  }
  init();
  for (int i = 1; i <= M; i++) {
    l = read();
    r = read();
    ask[i] = quest{l + 1, N - r, i};
  }
  sort(ask + 1, ask + 1 + M, cmp1);
  pos = 1;
  for (int i = 1; i <= M; i++) {
    while (pos <= ask[i].r) {
      if (a[pos] >= 0) {
        l = 1;
        r = pos;
        while (l <= r) {
          m = l + r >> 1;
          if (sum(m) >= a[pos]) {
            l = m + 1;
          } else {
            r = m - 1;
          }
        }
        updata(1, 1);
        updata(r + 1, -1);
      }
      pos++;
    }
    ans[ask[i].id] = sum(ask[i].l);
  }
  for (int i = 1; i <= M; i++) {
    write(ans[i]);
  }
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}
