#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
const int inf = 0x3f3f3f3f;
int a[N], b[N];
int ans[N];
int n, q;
vector<pair<int, int> > que[N];
struct Seg {
  int tr[N];
  void add(int x, int v) {
    for (int i = x; i <= n; i += i & -i) tr[i] += v;
  }
  int sum(int x) {
    int res = 0;
    for (int i = x; i; i -= i & -i) res += tr[i];
    return res;
  }
  int query(int x) {
    int cnt = 0, cur = 0;
    for (int i = 21; i >= 0; --i) {
      cur += (1 << i);
      if (cur > n || cnt + tr[cur] < x)
        cur -= (1 << i);
      else
        cnt += tr[cur];
    }
    return cur;
  }
} seg;
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    if (a[i] > i)
      b[i] = inf;
    else
      b[i] = i - a[i];
  }
  for (int i = 1; i <= q; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    que[n - y].push_back({x + 1, i});
  }
  for (int r = 1; r <= n; ++r) {
    int L = seg.query(b[r]);
    L = min(L, r - 1);
    if (L + 1 >= 1) {
      seg.add(1, 1);
      seg.add(L + 1, -1);
    }
    if (b[r] == 0) {
      seg.add(r, 1);
      seg.add(r + 1, -1);
    }
    for (auto it : que[r]) {
      int l = it.first;
      int id = it.second;
      ans[id] = seg.sum(l);
    }
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
}
