#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 int N = 1 << 20;
int n, q, a[N], xx, yy, ans[N];
vector<pair<int, int>> qry[N];
vector<int> active[N];
int parent[N], Rank[N], del[N];
int find_set(int i) {
  if (parent[i] == i) return i;
  return parent[i] = find_set(parent[i]);
}
void join(int i, int j) {
  i = find_set(i);
  j = find_set(j);
  if (i == j) return;
  if (Rank[i] > Rank[j]) swap(i, j);
  if (Rank[i] == Rank[j]) ++Rank[j];
  del[j] = min(del[i], del[j]);
  parent[i] = j;
}
int multi_set[N];
void add_set(int i, int v) {
  for (i++; i <= N; i += i & (-i)) multi_set[i - 1] += v;
}
int get_by_index(int t) {
  int s = 0;
  for (int sz = N >> 1; sz; sz >>= 1)
    if (multi_set[(s + sz) - 1] < t) t -= multi_set[(s += sz) - 1];
  return s;
}
int tree[N];
int cum(int i) {
  if (i == -1) return -1;
  int res = 0;
  for (i++; i; i -= i & (-i)) res += tree[i - 1];
  return res;
}
void insert(int i) {
  for (i++; i <= N; i += i & (-i)) ++tree[i - 1];
}
bool Never_give_up() {
  scanf("%d%d", &n, &q);
  iota(parent, parent + n + 1, 0);
  int sz = 0;
  add_set(0, -1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    a[i] = i - a[i];
    if (a[i] < 0) a[i] = 1e9 + 5;
    if (a[i] == 0)
      del[i] = i;
    else if (sz >= a[i])
      del[i] = get_by_index(sz - a[i]);
    else
      del[i] = 1e9 + 5;
    if (del[i] <= n) join(i, del[i]);
    del[i] = del[find_set(i)];
    if (del[i] <= n) {
      ++sz;
      add_set(del[i], 1);
      active[del[i]].push_back(i);
    }
  }
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &xx, &yy);
    qry[xx + 1].push_back({n - yy, i});
  }
  for (int i = n; i >= 1; --i) {
    for (int j : active[i]) insert(j);
    for (auto go : qry[i]) {
      int l = i;
      int r = go.first;
      int j = go.second;
      ans[j] = cum(r) - cum(l - 1);
    }
  }
  for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
  return 0;
}
int main() {
  int t = 1;
  while (t--) {
    Never_give_up();
  }
  return 0;
}
