Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated).

The weight of a is defined as the maximum number of elements you can remove.

You must answer q independent queries (x, y): after replacing the x first elements of a and the y last elements of a by n+1 (making them impossible to remove), what would be the weight of a?

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 3 ⋅ 10^5) — the length of the array and the number of queries.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — elements of the array.

The i-th of the next q lines contains two integers x and y (x, y ≥ 0 and x+y < n).

Output

Print q lines, i-th line should contain a single integer — the answer to the i-th query.

Examples

Input


13 5
2 2 3 9 5 4 6 5 7 8 3 11 13
3 1
0 0
2 4
5 0
0 12


Output


5
11
6
1
0


Input


5 2
1 4 1 2 4
0 0
1 0


Output


2
0

Note

Explanation of the first query:

After making first x = 3 and last y = 1 elements impossible to remove, a becomes [×, ×, ×, 9, 5, 4, 6, 5, 7, 8, 3, 11, ×] (we represent 14 as × for clarity).

Here is a strategy that removes 5 elements (the element removed is colored in red):

  * [×, ×, ×, 9, \color{red}{5}, 4, 6, 5, 7, 8, 3, 11, ×] 
  * [×, ×, ×, 9, 4, 6, 5, 7, 8, 3, \color{red}{11}, ×] 
  * [×, ×, ×, 9, 4, \color{red}{6}, 5, 7, 8, 3, ×] 
  * [×, ×, ×, 9, 4, 5, 7, \color{red}{8}, 3, ×] 
  * [×, ×, ×, 9, 4, 5, \color{red}{7}, 3, ×] 
  * [×, ×, ×, 9, 4, 5, 3, ×] (final state) 



It is impossible to remove more than 5 elements, hence the weight is 5.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Task5 {
    int[] tree;
    int[] lazy;
    int[] max;
    int n;

    private void push(int node) {
        max[node * 2] += lazy[node];
        max[node * 2 + 1] += lazy[node];
        lazy[node  *2] += lazy[node];
        lazy[node * 2 + 1] += lazy[node];
        lazy[node] = 0;
    }

    private void add(int from, int to,  int a, int b, int node) {
        if (from <= a && b <= to) {
            tree[node]++;
            max[node]++;
            lazy[node]++;
            return;
        }

        push(node);

        int mid = (a + b) / 2;
        if (from <= mid) add(from, to, a, mid, node * 2);
        if (to > mid) add(from, to, mid + 1, b, node * 2 + 1);

        max[node] = Math.max(max[node * 2], max[node * 2 + 1]);
    }

    private int getValue(int index, int a, int b, int node) {
        if (a == b) return tree[node];

        int mid = (a + b) / 2;
        if (index <= mid) return getValue(index, a, mid, node  * 2) + tree[node];
        return getValue(index, mid + 1, b, node * 2  +1) + tree[node];
    }


    private int getLastAtLeast(int num, int a, int b, int node, int sum) {
        sum += tree[node];
        if (a == b) {
            if (sum >= num) return a;
            else return -1;
        }

        push(node);

        int mid = (a + b) / 2;
        if (max[node  *2 + 1] >= num) return getLastAtLeast(num, mid + 1, b, node * 2 + 1, sum);
        return getLastAtLeast(num, a, mid, node * 2, sum);
    }

    public static void main(String[] args) throws IOException {
        new Task5().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        n = Integer.parseInt(tokenizer.nextToken());
        int q = Integer.parseInt(tokenizer.nextToken());

        int[] nums = new int[n];
        tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(tokenizer.nextToken()) - 1;
        }

        tree = new int[4 * n];
        max = new int[4 * n];
        lazy = new int[4 * n];

        ArrayList<int[]>[] queries = new ArrayList[n];
        for (int i = 0; i < n; i++) queries[i] = new ArrayList<int[]>();
        for (int q1 = 0; q1 < q; q1++) {
            tokenizer = new StringTokenizer(f.readLine());
            int a = Integer.parseInt(tokenizer.nextToken());
            int b = Integer.parseInt(tokenizer.nextToken());
            int[] ar = {a, q1};
            queries[n - 1 - b].add(ar);
        }

        tree = new int[4 * n];
        int[] queryRes = new int[q];
        for (int i = 0; i < n; i++) {
            if (nums[i] < i) {
                int lastAtLeast = getLastAtLeast(i - nums[i], 0, n - 1, 1, 0);
                if (lastAtLeast != -1) add(0, Math.min(lastAtLeast, i), 0, n - 1, 1);
            } else if (nums[i] == i) {
                add(0, i, 0, n - 1, 1);
            }

            for (int[] query : queries[i]) {
                int res = getValue(query[0], 0, n - 1, 1);
                queryRes[query[1]] = res;
            }
        }


        for (int res : queryRes) {
            out.println(res);
        }

        out.close();
    }

    private static class ArrayComparator implements Comparator<int[]> {
        @Override
        public int compare(int[] o1, int[] o2) {
            return Integer.compare(o1[1], o2[1]);
        }
    }
}
