#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, q, a[N], lazy[4 * N], ans, res[N];
vector<pair<int, int> > query[N];
pair<int, int> ST1[4 * N];
struct P {
  int num;
} ST[4 * N];
void update_num(int id, int l, int r, int pos, int val) {
  if (l > pos || r < pos) return;
  if (l == r) {
    ST[id].num = val;
    return;
  }
  int mid = (l + r) / 2;
  update_num(id * 2, l, mid, pos, val);
  update_num(id * 2 + 1, mid + 1, r, pos, val);
  ST[id].num = ST[id * 2].num + ST[id * 2 + 1].num;
}
int get_num(int id, int l, int r, int L, int R) {
  if (r < L || R < l) return 0;
  if (L <= l && r <= R) return ST[id].num;
  int mid = (l + r) / 2;
  return get_num(id * 2, l, mid, L, R) + get_num(id * 2 + 1, mid + 1, r, L, R);
}
void build(int id, int l, int r) {
  if (l == r) {
    if (l - a[l] >= 0)
      ST1[id] = make_pair(l - a[l], l);
    else
      ST1[id] = make_pair(1e9, l);
    return;
  }
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  ST1[id] = min(ST1[id * 2], ST1[id * 2 + 1]);
}
void dolazy(int id, int l, int r) {
  if (lazy[id] == 0) return;
  ST1[id].first += lazy[id];
  if (l != r) {
    lazy[id * 2] += lazy[id];
    lazy[id * 2 + 1] += lazy[id];
  }
  lazy[id] = 0;
}
void update(int id, int l, int r, int L, int R, int val) {
  dolazy(id, l, r);
  if (r < L || R < l) return;
  if (L <= l && r <= R) {
    ST1[id].first += val;
    if (l != r) {
      lazy[id * 2] += val;
      lazy[id * 2 + 1] += val;
    }
    return;
  }
  int mid = (l + r) / 2;
  update(id * 2, l, mid, L, R, val);
  update(id * 2 + 1, mid + 1, r, L, R, val);
  ST1[id] = min(ST1[id * 2], ST1[id * 2 + 1]);
}
void get(int id, int l, int r, int L, int R) {
  dolazy(id, l, r);
  if (r < L || R < l || ans != -1 || ST1[id].first > 0) return;
  int mid = (l + r) / 2;
  if (L <= l && r <= R) {
    if (l == r) {
      ans = l;
      return;
    }
    dolazy(id * 2, l, mid);
    dolazy(id * 2 + 1, mid + 1, r);
    if (ST1[id * 2].first <= 0)
      get(id * 2, l, mid, L, R);
    else
      get(id * 2 + 1, mid + 1, r, L, R);
    return;
  }
  get(id * 2, l, mid, L, R);
  get(id * 2 + 1, mid + 1, r, L, R);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  for (int i = 1; i < N * 4; i++) ST[i].num = 0;
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    l = 1 + l;
    r = n - r;
    query[l].push_back(make_pair(r, i));
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == i) {
      int j = i;
      while (true) {
        update_num(1, 1, n, j, 1);
        update(1, 1, n, j, n, -1);
        ans = -1;
        get(1, 1, n, j + 1, n);
        update(1, 1, n, j, j, 1e9);
        if (ans == -1) break;
        j = ans;
      }
    }
    for (auto& x : query[i]) {
      res[x.second] = get_num(1, 1, n, i, x.first);
    }
  }
  for (int i = 1; i <= q; i++) cout << res[i] << '\n';
}
