#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
int n, q;
int a[300005];
int ans[300005];
vector<pair<int, int> > e[300005];
int f[300005];
void add(int i, int x) {
  for (; i <= n; i += i & -i) {
    f[i] += x;
  }
}
int get(int i) {
  int v = 0;
  for (; i > 0; i -= i & -i) {
    v += f[i];
  }
  return v;
}
int get_idx(int x, int bd) {
  int v = 0, pos = 0;
  for (int i = 19; i >= 0; --i) {
    if (pos + (1 << i) <= bd && v + f[pos + (1 << i)] >= x) {
      pos += 1 << i;
      v += f[pos];
    }
  }
  return pos;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] = i - a[i];
  }
  for (int i = 1, x, y; i <= q; ++i) {
    cin >> x >> y;
    e[n - y].push_back({i, x + 1});
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] >= 0) {
      int idx = get_idx(a[i] - cnt, i);
      add(idx + 1, -1);
      ++cnt;
    }
    for (auto x : e[i]) {
      ans[x.first] = cnt + get(x.second);
    }
  }
  for (int i = 1; i <= q; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
