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.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int numQueries = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt() - 1;
            }
            Query[] queries = new Query[numQueries];
            int[] ans = new int[numQueries];
            for (int i = 0; i < numQueries; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                queries[i] = new Query();
                queries[i].l = x;
                queries[i].r = n - y - 1;
                queries[i].id = i;
            }

            int[] when = new int[n];
            Arrays.fill(when, -1);

            for (int i = n - 1; i >= 0; i--) {
                a[i] = i - a[i];
            }

//        // Slow version.
//        for (int i = n - 1; i >= 0; i--) {
//            while (true) {
//                int found = -1;
//                for (int j = n - 1; j >= i; j--) {
//                    if (a[j] == 0) {
//                        when[j] = i;
//                        found = j;
//                        break;
//                    }
//                }
//                if (found < 0) {
//                    break;
//                }
//                for (int j = found; j < n; j++) {
//                    a[j] -= 1;
//                }
//            }
//        }

            IntervalTree tree = new IntervalTree(n);
            for (int i = n - 1; i >= 0; i--) {
                if (a[i] < 0) {
                    a[i] = n + 1;
                }
                tree.add(i, i + 1, a[i]);

                while (true) {
                    int[] m = tree.getMin(i, n);
                    if (m[1] < 0) {
                        tree.add(m[0], m[0] + 1, n + 1);
                        continue;
                    }
                    if (m[1] > 0) {
                        break;
                    }

                    int p = m[0]; // rightmost zero
                    when[p] = i;
                    tree.add(p, n, -1);
                }
            }

            Arrays.sort(queries, (u, v) -> -(u.r - v.r));
            int qpos = 0;
            FenwickTree ft = new FenwickTree(n);
            for (int i = 0; i < n; i++) {
                if (when[i] >= 0) {
                    ft.add(when[i], 1);
                }
            }
            for (int i = n - 1; i >= 0; i--) {
                while (qpos < numQueries && queries[qpos].r == i) {
                    ans[queries[qpos].id] = ft.sum(queries[qpos].l, n - 1);
                    ++qpos;
                }
                if (when[i] >= 0) {
                    ft.add(when[i], -1);
                }
            }

            for (int i = 0; i < numQueries; i++) {
                out.println(ans[i]);
            }
        }

        class Query {
            int l;
            int r;
            int id;

        }

        class IntervalTree {
            int n;
            int[] add;
            int[] min;
            int[] minAt;
            final int infinity = (int) 1e9;

            IntervalTree(int n) {
                this.n = n;
                add = new int[4 * n];
                min = new int[4 * n];
                minAt = new int[4 * n];
                build(0, 0, n);
            }

            void add(int l, int r, int val) {
                addImpl(0, 0, n, l, r, val);
            }

            int[] getMin(int l, int r) {
                return getMinImpl(0, 0, n, l, r);
            }

            void build(int root, int rl, int rr) {
                if (rl + 1 == rr) {
                    minAt[root] = rl;
                    return;
                }
                int rm = (rl + rr) / 2;
                build(2 * root + 1, rl, rm);
                build(2 * root + 2, rm, rr);
            }

            void addImpl(int root, int rl, int rr, int l, int r, int val) {
                if (l < rl) {
                    l = rl;
                }
                if (r > rr) {
                    r = rr;
                }
                if (l >= r) {
                    return;
                }
                if (l == rl && r == rr) {
                    add[root] += val;
                    return;
                }
                int rm = (rl + rr) / 2;
                push(root);
                addImpl(2 * root + 1, rl, rm, l, r, val);
                addImpl(2 * root + 2, rm, rr, l, r, val);
                pull(root);
            }

            private int[] getMinImpl(int root, int rl, int rr, int l, int r) {
                if (l < rl) {
                    l = rl;
                }
                if (r > rr) {
                    r = rr;
                }
                if (l >= r) {
                    return new int[]{-1, infinity};
                }
                if (l == rl && r == rr) {
                    return new int[]{minAt[root], add[root] + min[root]};
                }
                int rm = (rl + rr) / 2;
                push(root);
                int[] lMin = getMinImpl(2 * root + 1, rl, rm, l, r);
                int[] rMin = getMinImpl(2 * root + 2, rm, rr, l, r);
                pull(root);
                if (lMin[1] < rMin[1]) {
                    return lMin;
                }
                return rMin;
            }

            private void push(int root) {
                add[2 * root + 1] += add[root];
                add[2 * root + 2] += add[root];
                add[root] = 0;
            }

            private void pull(int root) {
                int lm = min[2 * root + 1] + add[2 * root + 1];
                int rm = min[2 * root + 2] + add[2 * root + 2];
                if (lm < rm) {
                    min[root] = lm;
                    minAt[root] = minAt[2 * root + 1];
                } else {
                    min[root] = rm;
                    minAt[root] = minAt[2 * root + 2];
                }
            }

        }

        class FenwickTree {
            int[] a;

            FenwickTree(int n) {
                a = new int[n];
            }

            public void add(int pos, int val) {
                while (pos < a.length) {
                    a[pos] += val;
                    pos |= pos + 1;
                }
            }

            public int sum(int l, int r) {
                if (l > r) {
                    return 0;
                }
                return sum(r) - sum(l - 1);
            }

            public int sum(int r) {
                int res = 0;
                while (r >= 0) {
                    res += a[r];
                    r = (r & (r + 1)) - 1;
                }
                return res;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

