#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 998244353;
int sum[maxn << 2], add[maxn << 2];
inline void push_up(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
inline void push_down(int rt, int m) {
  if (add[rt]) {
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    sum[rt << 1] += (m - (m >> 1)) * add[rt];
    sum[rt << 1 | 1] += (m >> 1) * add[rt];
    add[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  add[rt] = 0;
  if (l == r) {
    sum[rt] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
inline void updata(int a, int b, long long c, int l, int r, int rt) {
  if (a <= l && b >= r) {
    sum[rt] += (r - l + 1) * c;
    add[rt] += c;
    return;
  }
  push_down(rt, r - l + 1);
  int mid = (l + r) >> 1;
  if (a <= mid) updata(a, b, c, l, mid, rt << 1);
  if (b > mid) updata(a, b, c, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
inline int query(int a, int b, int l, int r, int rt) {
  if (a <= l && b >= r) return sum[rt];
  push_down(rt, r - l + 1);
  int mid = (l + r) >> 1;
  int ans = 0;
  if (a <= mid) ans += query(a, b, l, mid, rt << 1);
  if (b > mid) ans += query(a, b, mid + 1, r, rt << 1 | 1);
  return ans;
}
inline int kth(int l, int r, int p, int rt) {
  if (l == r) return l;
  push_down(rt, r - l + 1);
  int mid = (l + r) >> 1;
  if (sum[rt << 1] >= p)
    return kth(l, mid, p, rt << 1);
  else
    return kth(mid + 1, r, p - sum[rt << 1], rt << 1 | 1);
}
int a[maxn], lim[maxn], ans[maxn], n, m, cnt = 0;
struct point {
  int l, r, num;
} p[maxn];
bool cmp(point u, point v) { return u.r < v.r; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  build(1, n, 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (i - a[i] < 0)
      lim[i] = -1;
    else if (i - a[i] == 0) {
      lim[i] = i;
      cnt++;
      updata(i, i, 1, 1, n, 1);
    } else {
      int k = i - a[i];
      k = cnt - k + 1;
      if (k <= 0)
        lim[i] = -1;
      else {
        lim[i] = kth(1, n, k, 1);
        cnt++;
        updata(lim[i], lim[i], 1, 1, n, 1);
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    cin >> p[i].l >> p[i].r;
    p[i].l++;
    p[i].r = n - p[i].r;
    p[i].num = i;
  }
  sort(p + 1, p + 1 + m, cmp);
  build(1, n, 1);
  cnt = 1;
  for (int i = 1; i <= m; ++i) {
    while (cnt <= p[i].r) {
      if (~lim[cnt]) updata(1, lim[cnt], 1, 1, n, 1);
      cnt++;
    }
    ans[p[i].num] = query(p[i].l, p[i].l, 1, n, 1);
  }
  for (int i = 1; i <= m; ++i) cout << ans[i] << endl;
  return 0;
}
