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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CFixedPointRemoval solver = new CFixedPointRemoval();
        solver.solve(1, in, out);
        out.close();
    }

    static class CFixedPointRemoval {
        int[] tree;

        void update(int n, int nL, int nR, int idx, int v) {
            if (nL > idx || nR < idx)
                return;
            if (nL == idx && nR == idx) {
                tree[n] += v;
                return;
            }
            update(2 * n + 1, nL, (nL + nR) / 2, idx, v);
            update(2 * n + 2, (nL + nR) / 2 + 1, nR, idx, v);
            tree[n] = tree[2 * n + 1] + tree[2 * n + 2];
        }

        int query(int n, int nL, int nR, int l, int r) {
            if (nL > r || nR < l)
                return 0;
            if (l <= nL && nR <= r)
                return tree[n];
            return query(2 * n + 1, nL, (nL + nR) / 2, l, r) + query(2 * n + 2, (nL + nR) / 2 + 1, nR, l, r);
        }

        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt(), q = s.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = s.nextInt() - 1;
            tree = new int[4 * n];
            int[] st = new int[n];
            for (int i = 0; i < n; i++) {
                if (i - a[i] >= 0) {
                    int v = i - a[i];
                    if (v != 0) {
                        int l = 0, r = i - 1;
                        int ans = -1;
                        while (l <= r) {
                            int m = (l + r) / 2;
                            if (query(0, 0, n - 1, m, i - 1) >= v) {
                                ans = m;
                                l = m + 1;
                            } else
                                r = m - 1;
                        }
                        st[i] = ans;
                    } else
                        st[i] = i;
                } else
                    st[i] = -1;
                if (st[i] != -1)
                    update(0, 0, n - 1, st[i], 1);
            }
            ArrayList<Integer>[] adj = new ArrayList[n];
            for (int i = 0; i < n; i++)
                adj[i] = new ArrayList<>();
            Arrays.fill(tree, 0);
            for (int i = 0; i < n; i++) {
                if (st[i] >= 0) {
                    update(0, 0, n - 1, i, 1);
                    adj[st[i]].add(i);
                }
            }
            int[] res = new int[q];
            ArrayList<Pair>[] que = new ArrayList[n];
            for (int i = 0; i < n; i++)
                que[i] = new ArrayList<>();
            for (int i = 0; i < q; i++) {
                int l = s.nextInt(), r = n - 1 - s.nextInt();
                que[l].add(new Pair(i, r));
            }
            for (int i = 0; i < n; i++) {
                for (Pair p : que[i]) {
                    res[p.i] = query(0, 0, n - 1, i, p.r);
                }
                for (int x : adj[i]) {
                    update(0, 0, n - 1, x, -1);
                }
            }
            for (int i = 0; i < q; i++)
                w.println(res[i]);
        }

        class Pair {
            int i;
            int r;

            Pair(int i, int r) {
                this.i = i;
                this.r = r;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

