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.*;
public class Ediv2 {
	
	static final int BLOCK_SIZE = 480;

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int[] mins = new int[n];
		int[] init = new int[n];
		SegmentTreeSumDelta st = new SegmentTreeSumDelta(init);
		for(int i = 0; i < n; i++) {
			int d = i+1 - arr[i];
			if(d < 0) {
				mins[i] = -1;
			}
			else if(d == 0) {
				mins[i] = i;
				st.update_point(i, 1);
			}
			else if(st.rSq(0, i) < d) {
				mins[i] = -1;
			}
			else {
				int a = 0, b = i;
				while(b - a > 1) {
					int c = (a+b)/2;
					if(st.rSq(c, i) >= d) a = c;
					else b = c;
				}
				mins[i] = a;
				st.update_point(a, 1);
			}
		}
		ArrayList<Integer>[] poss = new ArrayList[n];
		for(int i = 0; i < n; i++) poss[i] = new ArrayList<>();
		init = new int[n];
		for(int i = 0; i < n; i++) {
			if(mins[i] >= 0) {
				poss[mins[i]].add(i);
				init[i] = 1;
			}
		}
		ArrayList<Pair>[] ps = new ArrayList[n];
		for(int i = 0; i < n; i++) ps[i] = new ArrayList<>();
		for(int i = 0; i < q; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			ps[a].add(new Pair(a, n-1-b, i));
		}
		SegmentTreeSumDelta st2 = new SegmentTreeSumDelta(init);
		int[] res = new int[q];
		for(int a = 0; a < n; a++) {
			for(Pair p: ps[a]) {
				res[p.i] = st2.rSq(a, p.b);
			}
			for(int i: poss[a]) st2.update_point(i, -1);
		}
	    StringBuilder sb = new StringBuilder();
	    for(int r: res) sb.append(r+"\n");
	    PrintWriter pw = new PrintWriter(System.out);
	    pw.print(sb.toString());
	    pw.flush();
	}
	
	static class Pair{
		int a, b, i;
		public Pair(int a, int b, int i) {
			this.a = a; this.b = b; this.i = i;
		}
	}
	
	static class SegmentTreeSumDelta {
		private int[] st; private int[] A;
		private int n;
		private int left (int p) { return p << 1; }
		private int right(int p) { return (p << 1) + 1; }
		
		static int neutral = 0;
		static int op(int x, int y) {
			return x + y;
		}

		private void build(int p, int L, int R) {
			if (L == R) 
				st[p] = A[L]; 
			else {  
				build(left(p) , L              , (L + R) / 2);
				build(right(p), (L + R) / 2 + 1, R          );
				int v1 = st[left(p)], v2 = st[right(p)];
				st[p] = op(v1, v2);
			} }

		private int rSq(int p, int L, int R, int i, int j) {
			if (i >  R || j <  L) return neutral;
			if (L >= i && R <= j) return st[p]; 

			// compute the min values in the left and right part of the interval
			int v1 = rSq(left(p) , L              , (L+R) / 2, i, j);
			int v2 = rSq(right(p), (L+R) / 2 + 1, R          , i, j);

			return op(v1, v2);
		}

		private int update_point(int p, int L, int R, int idx, int delta) {
			int i = idx, j = idx;

			if (i > R || j < L)
				return st[p];

			if (L == i && R == j) {
				A[i] += delta;
				return st[p] = A[L];
			}

			int v1, v2;
			v1 = update_point(left(p) , L              , (L + R) / 2, idx, delta);
			v2 = update_point(right(p), (L + R) / 2 + 1, R          , idx, delta);

			return st[p] = op(v1, v2);
		}

		public SegmentTreeSumDelta(int[] _A) {
			A = _A; n = A.length; 
			st = new int[4 * n];
			Arrays.fill(st, neutral);
			build(1, 0, n - 1);
		}

		public int rSq(int i, int j) { return rSq(1, 0, n - 1, i, j); } // overloading

		public int update_point(int idx, int delta) {
			return update_point(1, 0, n - 1, idx, delta); }
	}
	
	static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }

}
