#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int mini[1100000], d[1100000], val[300005], n, a[300005], ans[300005], now;
vector<pair<int, int> > qus[300005];
void up(int x, int y) {
  while (x <= n) {
    val[x] += y;
    x += x & -x;
  }
}
int get(int x) {
  int sum = 0;
  while (x) {
    sum += val[x];
    x -= x & -x;
  }
  return sum;
}
set<int> s;
void pd(int x, int l, int r) {
  if (l != r) {
    mini[(x << 1)] += d[x];
    mini[((x << 1) | 1)] += d[x];
    d[(x << 1)] += d[x];
    d[((x << 1) | 1)] += d[x];
  }
  d[x] = 0;
}
void build(int x, int l, int r) {
  if (l == r) {
    if (a[l] < 0)
      mini[x] = 1e9;
    else
      mini[x] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build((x << 1), l, mid);
  build(((x << 1) | 1), mid + 1, r);
  mini[x] = min(mini[(x << 1)], mini[((x << 1) | 1)]);
}
void update(int x, int l, int r, int tl, int tr, int p) {
  pd(x, l, r);
  if (l >= tl && r <= tr) {
    mini[x] += p;
    d[x] += p;
    return;
  }
  if (l > tr || tl > r) return;
  int mid = (l + r) >> 1;
  update((x << 1), l, mid, tl, tr, p);
  update(((x << 1) | 1), mid + 1, r, tl, tr, p);
  mini[x] = min(mini[(x << 1)], mini[((x << 1) | 1)]);
}
void ch(int x, int l, int r) {
  pd(x, l, r);
  if (mini[x] >= 0) return;
  if (l == r) {
    mini[x] = 1e9;
    return;
  }
  int mid = (l + r) >> 1;
  ch((x << 1), l, mid);
  ch(((x << 1) | 1), mid + 1, r);
  mini[x] = min(mini[(x << 1)], mini[((x << 1) | 1)]);
}
void find(int x, int l, int r) {
  pd(x, l, r);
  if (mini[x] > 0) return;
  if (r < now) return;
  if (l == r) {
    up(l, 1);
    s.emplace(l);
    return;
  }
  int mid = (l + r) >> 1;
  find((x << 1), l, mid);
  find(((x << 1) | 1), mid + 1, r);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i], a[i] = i - a[i];
  for (int i = 1; i <= q; i++) {
    int x, y;
    cin >> x >> y;
    qus[x + 1].emplace_back(make_pair(n - y, i));
  }
  build(1, 1, n);
  for (int i = n; i >= 1; i--) {
    now = i;
    if (!a[i]) {
      s.clear();
      s.emplace(i);
      up(i, 1);
      while (!s.empty()) {
        int it = *s.begin();
        s.erase(s.begin());
        update(1, 1, n, it, n, -1);
        ch(1, 1, n);
        find(1, 1, n);
      }
    }
    for (auto u : qus[i]) {
      ans[u.second] = get(u.first);
    }
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
  return 0;
}
