#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3e5 + 100;
int a[N], ans[N];
vector<pair<int, int>> pos[N];
struct Node {
  int l, r;
  int sum;
} tree[N << 2];
void build(int k, int l, int r) {
  tree[k].l = l;
  tree[k].r = r;
  tree[k].sum = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
}
void update(int k, int pos) {
  if (tree[k].l == tree[k].r) {
    tree[k].sum++;
    return;
  }
  int mid = tree[k].l + tree[k].r >> 1;
  if (pos <= mid)
    update(k << 1, pos);
  else
    update(k << 1 | 1, pos);
  tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;
}
int query_k(int k, int x) {
  if (tree[k].l == tree[k].r) return tree[k].l;
  if (tree[k << 1 | 1].sum >= x)
    return query_k(k << 1 | 1, x);
  else
    return query_k(k << 1, x - tree[k << 1 | 1].sum);
}
int query(int k, int l, int r) {
  if (tree[k].l > r || tree[k].r < l) return 0;
  if (tree[k].l >= l && tree[k].r <= r) return tree[k].sum;
  return query(k << 1, l, r) + query(k << 1 | 1, l, r);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    a[i] = i - a[i];
    if (a[i] < 0) a[i] = inf;
  }
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l++;
    r = n - r;
    pos[r].emplace_back(l, i);
  }
  build(1, 1, n);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      update(1, i);
      num++;
    } else if (num >= a[i]) {
      update(1, query_k(1, a[i]));
      num++;
    }
    for (pair<int, int> t : pos[i]) ans[t.second] = query(1, t.first, n);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
