#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 4e5 + 10;
const long long big = 1e18;
const long long block = 500;
const long long mod = 1e9 + 7;
long long t, n, q;
long long a[N + 1];
long long b[N + 1];
struct seg {
  long long t[4 * N] = {0};
  void upd(long long p, long long v = 1, long long l = 0, long long r = n + 2) {
    if (l == r) return (void)(t[v]++);
    long long m = l + r >> 1;
    if (p <= m)
      upd(p, v * 2, l, m);
    else
      upd(p, v * 2 + 1, m + 1, r);
    t[v]++;
  }
  long long get(long long l, long long r, long long v = 1, long long tl = 0,
                long long tr = n + 2) {
    if (l > tr || tl > r) return 0;
    if (l <= tl && tr <= r) return t[v];
    long long m = tl + tr >> 1;
    return get(l, r, v * 2, tl, m) + get(l, r, v * 2 + 1, m + 1, tr);
  }
} rt;
struct node {
  node *l, *r;
  long long z;
  node() {
    l = r = nullptr;
    z = 0;
  }
} * per[N] = {nullptr};
void bld(node *v, long long l = 0, long long r = n + 5) {
  if (l == r) return;
  long long m = l + r >> 1;
  bld(v->l = new node(), l, m);
  bld(v->r = new node(), m + 1, r);
}
void upd(long long p, node *u, node *v, long long l = 0, long long r = n + 5) {
  if (l == r) {
    u->z = v->z + 1;
    return;
  }
  long long m = l + r >> 1;
  if (p <= m) {
    u->r = v->r;
    upd(p, u->l = new node(), v->l, l, m);
  } else {
    u->l = v->l;
    upd(p, u->r = new node(), v->r, m + 1, r);
  }
  u->z = u->l->z + u->r->z;
}
long long get2(long long l, long long r, node *v, long long tl = 0,
               long long tr = n + 5) {
  if (l > tr || tl > r) return 0;
  if (l <= tl && tr <= r) {
    return v->z;
  }
  long long m = (tl + tr >> 1);
  return get2(l, r, v->l, tl, m) + get2(l, r, v->r, m + 1, tr);
}
void solve() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == i)
      b[i] = i;
    else if (a[i] > i) {
      b[i] = 0;
    } else {
      long long z = i - a[i];
      long long l = 0, r = i, ans = -1;
      while (l <= r) {
        long long m = (l + r) >> 1;
        if (rt.get(m + 1, n + 1) >= z) {
          l = m + 1;
          ans = m;
        } else
          r = m - 1;
      }
      b[i] = ans + 1;
    }
    rt.upd(b[i]);
  }
  per[0] = new node(), bld(per[0]);
  for (int i = 1; i <= n; i++) {
    per[i] = new node();
    upd(b[i], per[i], per[i - 1]);
  }
  while (q--) {
    long long x, y;
    cin >> x >> y;
    long long z = n - y;
    cout << get2(x + 1, n + 1, per[z]) << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  t = 1;
  while (t--) {
    solve();
  }
}
