#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, lg = 20;
int n, q, a[N];
vector<pair<int, int> > qr[N];
int t[N], id[N], ans[N];
void add(int first, int v) {
  for (int i = first; i <= n; i += (i & (-i))) t[i] += v;
  return;
}
int cal(int first) {
  int res = 0;
  for (int i = first; i > 0; i -= i & (-i)) res += t[i];
  return res;
}
int find(int k) {
  int sum = 0, pos = 0;
  for (int i = (lg), _x = (0); i >= _x; i--) {
    pos += (1 << i);
    if (pos > n || sum + t[pos] > k)
      pos -= (1 << i);
    else
      sum += t[pos];
  }
  return pos;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = (1), _x = (n); i <= _x; i++) scanf("%d", &a[i]);
  int l, r;
  for (int i = (1), _x = (q); i <= _x; i++) {
    scanf("%d%d", &l, &r);
    l++, r = n - r;
    qr[r].push_back(make_pair(l, i));
  }
  int ed = n + 1;
  for (int i = (1), _x = (n); i <= _x; i++) {
    ed--;
    int d = i - a[i];
    int p = find(d - 1);
    if (p == 0) {
      if (d == 0) add(ed, 1);
    } else
      add(p + 1, 1);
    for (int j = (0), _x = ((int)(qr[i]).size() - 1); j <= _x; j++) {
      int l = qr[i][j].first, id = qr[i][j].second;
      ans[id] = cal(n - l + 1);
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
