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.util.*;
import java.io.*;
import java.text.*;

public class CF_1404_C{
    //SOLUTION BEGIN
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int N = ni(), Q = ni();
        int[] A = new int[N];
        for(int i = 0; i< N; i++){
            A[i] = i-(ni()-1);
            if(A[i] < 0)A[i] = INF;
        }
        SegmentTree sum = new SegmentTree(N);
        LazySegmentTree st = new LazySegmentTree(N);
        for(int i = 0; i< N; i++)st.modify(i, i, A[i]);
        int[][] qu = new int[Q][];
        for(int i = 0; i< Q; i++){
            int x = ni(), y = ni();
            qu[i] = new int[]{i, x, N-y-1};
        }
        Arrays.sort(qu, (int[] i1, int[] i2) -> Integer.compare(i2[1], i1[1]));
        int ptr = 0;
        int[] ans = new int[Q];
        for(int i = N-1; i>= 0; i--){
            while(st.query(i, N-1) == 0){
                int idx = st.rightZero(1);
                sum.update(idx, 1);
                st.modify(idx, idx, INF);
                st.modify(idx, N-1, -1);
            }
            while(ptr < Q && qu[ptr][1] == i){
                ans[qu[ptr][0]] = sum.query(i, qu[ptr][2]);
                ptr++;
            }
        }
        for(int i:ans)pn(i);
    }
    class SegmentTree{
        int m= 1;
        int[] t;
        public SegmentTree(int n){
            while(m<n)m<<=1;
            t = new int[m<<1];
        }
        public void update(int pos, int delta){
            t[pos+=m]+=delta;
            for(pos>>=1;pos>0;pos>>=1)t[pos] = t[pos<<1]+t[pos<<1|1];
        }
        int query(int l, int r){
            int ans = 0;
            for(l+=m,r+=m+1;l<r;l>>=1,r>>=1){
                if((l&1)==1)ans+=t[l++];
                if((r&1)==1)ans+=t[--r];
            }
            return ans;
        }
    }
    class LazySegmentTree{
        int m = 1;
        int[] t, lazy;

        public LazySegmentTree(int N){
            while(m < N)m<<=1;
            t = new int[m<<1];
            lazy = new int[m<<1];
            for(int i = N; i< m; i++)t[m+i] = INF;
            for(int i = m-1; i> 0; i--)t[i] = Math.min(t[i<<1], t[i<<1|1]);
        }
        void push(int i){
            if(lazy[i] != 0){
                t[i] += lazy[i];
                if(i < m){
                    lazy[i<<1] += lazy[i];
                    lazy[i<<1|1] += lazy[i];
                }
                lazy[i] = 0;
            }
        }
        void u(int l, int r, int ll, int rr, int i, int x){
            push(i);
            if(l == ll && r == rr){
                lazy[i] += x;
                push(i);
                return;
            }
            int mid = (ll+rr)>>1;
            push(i<<1);
            push(i<<1|1);
            if(r <= mid)u(l, r, ll, mid, i<<1, x);
            else if(l > mid)u(l, r, mid+1, rr, i<<1|1, x);
            else{
                u(l, mid, ll, mid, i<<1, x);
                u(mid+1, r, mid+1, rr, i<<1|1, x);
            }
            t[i] = Math.min(t[i<<1], t[i<<1|1]);
        }
        void modify(int l, int r, int x){
            if(l <= r)u(l, r, 0, m-1, 1, x);
        }
        int query(int l, int r){
            return min(l, r, 0, m-1, 1);
        }
        int min(int l, int r, int ll, int rr, int i){
            push(i);
            if(l == ll && r == rr)return t[i];
            int mid = (ll+rr)>>1;
            if(r <= mid)return min(l, r, ll, mid, i<<1);
            else if(l > mid)return min(l, r, mid+1, rr, i<<1|1);
            else return Math.min(min(l, mid, ll, mid, i<<1), min(mid+1, r, mid+1, rr, i<<1|1));
        }
        int rightZero(int i) throws Exception{
            hold(t[i] == 0);
            if(i >= m)return i-m;
            push(i<<1);
            push(i<<1|1);
            if(t[i<<1|1] == 0)return rightZero(i<<1|1);
            return rightZero(i<<1);
        }
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
    final long IINF = (long)1e17;
    final int INF = (int)1e7+2;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = true, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        long ct = System.currentTimeMillis();
        if (fileIO) {
            in = new FastReader("");
            out = new PrintWriter("");
        } else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = multipleTC? ni():1;
        pre();
        for (int t = 1; t <= T; t++) solve(t);
        out.flush();
        out.close();
        System.err.println(System.currentTimeMillis() - ct);
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1404_C().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start();
        else new CF_1404_C().run();
    }
    int[][] make(int n, int e, int[] from, int[] to, boolean f){
        int[][] g = new int[n][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = to[i];
            if(f)g[to[i]][--cnt[to[i]]] = from[i];
        }
        return g;
    }
    int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){
        int[][][] g = new int[n][][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};
            if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};
        }
        return g;
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object... o){for(Object oo:o)out.print(oo+" ");}
    void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?" ":"\n"));}
    void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str;
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}