#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  char c = getchar(), f = 0;
  x = 0;
  while (!isdigit(c)) f = (c == '-'), c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x = f ? -x : x;
}
using namespace std;
const int N = 10001;
const int M = 300011;
const int HA = 998244353;
int n, q, a[M], b[M];
vector<pair<int, int> > Q[M];
namespace Segment_tree {
struct Node {
  int l, r, len;
  int num, add;
} node[M << 2];
inline void pushup(int x) {
  node[x].num = (node[(x << 1)].num + node[(x << 1 | 1)].num);
}
inline void pushdown(int x) {
  if (node[x].add == 0) return;
  node[(x << 1)].add += node[x].add;
  node[(x << 1)].num += node[(x << 1)].len * node[x].add;
  node[(x << 1 | 1)].add += node[x].add;
  node[(x << 1 | 1)].num += node[(x << 1 | 1)].len * node[x].add;
  node[x].add = 0;
}
void build(int x, int l, int r) {
  node[x].l = l, node[x].r = r;
  node[x].len = (r - l + 1);
  if (l == r) {
    return;
  }
  int mid = (l + r) >> 1;
  build((x << 1), l, mid), build((x << 1 | 1), mid + 1, r);
  pushup(x);
}
void range_add(int x, int ql, int qr, int val) {
  if (ql > qr) return;
  if (ql <= node[x].l && node[x].r <= qr) {
    node[x].add += val;
    node[x].num += val * node[x].len;
    return;
  }
  pushdown(x);
  int mid = (node[x].l + node[x].r) >> 1;
  if (ql <= mid) {
    range_add((x << 1), ql, qr, val);
  }
  if (mid + 1 <= qr) {
    range_add((x << 1 | 1), ql, qr, val);
  }
  pushup(x);
}
int range_query(int x, int ql, int qr) {
  if (ql <= node[x].l && node[x].r <= qr) {
    return node[x].num;
  }
  pushdown(x);
  int mid = (node[x].l + node[x].r) >> 1, ans = 0;
  if (ql <= mid) {
    ans += range_query((x << 1), ql, qr);
  }
  if (mid + 1 <= qr) {
    ans += range_query((x << 1 | 1), ql, qr);
  }
  return ans;
}
int find_pla(int x) {
  int l = 1, r = x, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (range_query(1, mid, mid) >= b[x]) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
}  // namespace Segment_tree
using namespace Segment_tree;
int ans[M];
int main() {
  read(n), read(q);
  for (int i = (1); i <= (n); i++) {
    read(a[i]);
    b[i] = i - a[i];
    if (b[i] < 0) b[i] = 0x3f3f3f3f;
  }
  for (int i = (1); i <= (q); i++) {
    int l, r;
    read(l), read(r);
    l += 1, r = n - r;
    Q[r].push_back(make_pair(l, i));
  }
  build(1, 1, n);
  for (int i = (1); i <= (n); i++) {
    int pla = find_pla(i);
    range_add(1, 1, pla, 1);
    for (int j = 0; j < Q[i].size(); j++) {
      ans[Q[i][j].second] = range_query(1, Q[i][j].first, Q[i][j].first);
    }
  }
  for (int i = (1); i <= (q); i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
