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.ArrayList;

public class Main {

	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		FastScanner fs = new FastScanner();
		java.io.PrintWriter out = new java.io.PrintWriter(System.out);
		solve(fs, out);
		out.flush();
	}

	private static final int INF = 1000000;

	public void solve(FastScanner fs, java.io.PrintWriter out) {
		int n = fs.nextInt(), q = fs.nextInt();
		int[] a = new int[n];
		for (int i = 0;i < n;++ i) a[i] = fs.nextInt();
		ArrayList<ArrayList<Query>> query = new ArrayList<>(n);
		for (int i = 0;i < n;++ i) query.add(new ArrayList<>());
		for (int i = 0;i < q;++ i) {
			int x = fs.nextInt(), y = fs.nextInt();
			query.get(x).add(new Query(i, y));
		}
		int[] ans = new int[q];
		FenwickTree seg1 = new FenwickTree(n);
		for (int i = 0, sum = 0;i < n;++ i) {
			if (i + 1 - a[i] < 0) a[i] = -1;
			else a[i] = sum - (i + 1 - a[i]);
			if (a[i] < 0) {
				a[i] = 2 * INF;
			} else {
				seg1.add(i, 1);
				++ sum;
			}
		}
		LazySegmentTree seg2 = new LazySegmentTree(a);
		for (int x = 0;x < n;++ x) {
			for (Query i : query.get(x)) ans[i.index] = seg1.sum(x, n - i.y);
			int erase = x;
			if (seg2.getNum(erase) >= INF ) continue;
			do {
				seg1.add(erase, -1);
				seg2.update(erase, erase + 1, 2 * INF);
				seg2.update(erase + 1, n, -1);
				int index = seg2.get();
				if (seg2.getNum(index) < 0) {
					erase = index;
				} else break;
			} while(true);
		}
		for (int i : ans) out.println(i);
	}

	private static class Query {
		final int index, y;
		Query(int index, int y) {
			this.index = index;
			this.y = y;
		}
	}

	private static class FenwickTree {
		final int[] sum;
		FenwickTree(int len) {
			sum = new int[len + 1];
		}
		public void add(int i, int n) {
			for (int id = i + 1;id < sum.length;id += (id & -id)) sum[id] += n;
		}
		public int sum(int l, int r) {
			return sum(r) - sum(l);
		}
		private int sum(int i) {
			int ret = 0;
			for (int id = i;id > 0;id -= (id & -id)) ret += sum[id];
			return ret;
		}
	}

	private static class LazySegmentTree {
		final int[] lazy;
		final Pair[] data;
		class Pair implements Cloneable{
			int num, min;
			Pair(int num, int min) {
				this.num = num;
				this.min = min;
			}
			@Override
			public Pair clone() {
				return new Pair(num, min);
			}
			public void set(Pair pair) {
				num = pair.num;
				min = pair.min;
			}
		}
		final int size, len;
		LazySegmentTree(int[] a) {
			len = Integer.highestOneBit(a.length) << 1;
			size = len << 1;
			lazy = new int[size];
			data = new Pair[size];
			for (int i = 0;i < len;++ i) data[i + len] = new Pair(i < a.length ? a[i] : 2 * INF, i);
			for (int i = len - 1;i > 0;-- i) {
				data[i] = new Pair(0,0);
				merge(i);
			}
		}

		private int min(int a, int b) {
			return data[a].num <= data[b].num ? a : b;
		}

		private void merge(int i) {
			data[i].set(data[min(i << 1, i << 1 | 1)]);
		}

		private void lazy(int i) {
			lazy[i] = Math.min(lazy[i], 2 * INF);
			data[i].num += lazy[i];
			data[i].num = Math.min(data[i].num, 2 * INF);
			if (i >= len) {
				lazy[i] = 0;
				return;
			}
			lazy[i << 1] += lazy[i];
			lazy[i << 1 | 1] += lazy[i];
			lazy[i] = 0;
		}

		public void update(int l, int r, int add) {
			update(l, r, 1, 0, len, len >> 1, add);
		}

		private void update(int l, int r, int i, int dl, int dr, int n, int add) {
			lazy(i);
			if (l >= dr || r <= dl) return;
			if (l <= dl && dr <= r) {
				lazy[i] += add;
				lazy(i);
				return;
			}
			update(l, r, i << 1, dl, dr - n, n >> 1, add);
			update(l, r, i << 1 | 1, dl + n, dr, n >> 1, add);
			merge(i);
		}

		public int getNum(int i) {
			update(i, i+1, 0);
			return data[i + len].num;
		}

		public int get() {
			return data[1].min;
		}
	}

	static class FastScanner {
		private final java.io.InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) return true;
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (java.io.IOException e) {
				e.printStackTrace();
			}
			return buflen > 0;
		}
		private byte readByte() {
			return hasNextByte() ? buffer[ptr++ ] : -1;
		}
		private static boolean isPrintableChar(byte c) {
			return 32 < c || c < 0;
		}
		private static boolean isNumber(int c) {
			return '0' <= c && c <= '9';
		}
		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++ ;
			return hasNextByte();
		}
		public String next() {
			if (!hasNext()) throw new java.util.NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			byte b;
			while (isPrintableChar(b = readByte())) sb.appendCodePoint(b);
			return sb.toString();
		}
		public final long nextLong() {
			if (!hasNext()) throw new java.util.NoSuchElementException();
			long n = 0;
			try {
				byte b = readByte();
				if (b == '-') {
					while(isNumber(b = readByte())) n = n * 10 + '0' - b;
					return n;
				} else if (!isNumber(b)) throw new NumberFormatException();
				do n = n * 10 + b - '0'; while (isNumber(b = readByte()));
			} catch (java.util.NoSuchElementException e) {
			}
			return n;
		}
		public final int nextInt() {
			if (!hasNext()) throw new java.util.NoSuchElementException();
			int n = 0;
			try {
				byte b = readByte();
				if (b == '-') {
					while(isNumber(b = readByte())) n = n * 10 + '0' - b;
					return n;
				} else if (!isNumber(b)) throw new NumberFormatException();
				do n = n * 10 + b - '0'; while (isNumber(b = readByte()));
			} catch (java.util.NoSuchElementException e) {
			}
			return n;
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
	public static class Arrays {
		public static void sort(final int[] array) {
			int l, min = 0xFFFFFFFF, max = 0;
			for (l = 0;l < array.length;++ l) {
				int i = array[l];
				min &= i;
				max |= i;
				if ((i & 0x80000000) == 0) break;
			}
			for (int r = l + 1;r < array.length;++ r) {
				int i = array[r];
				min &= i;
				max |= i;
				if ((i & 0x80000000) != 0) {
					array[r] = array[l];
					array[l ++] = i;
				}
			}
			int use = min ^ max, bit = Integer.highestOneBit(use & 0x7FFFFFFF);
			if (bit == 0) return;
			sort(array, 0, l, use, bit);
			sort(array, l, array.length, use, bit);
		}
		private static void sort(final int[] array, final int left, final int right, final int use, int digit) {
			if (right - left <= 96) {
				for (int i = left + 1;i < right;++ i) {
					int tmp = array[i], tmp2, j;
					for (j = i;j > left && (tmp2 = array[j - 1]) > tmp;-- j) array[j] = tmp2;
					array[j] = tmp;
				}
				return;
			}
			int l = left;
			while(l < right && (array[l] & digit) == 0) ++ l;
			for (int r = l + 1;r < right;++ r) {
				int i = array[r];
				if ((i & digit) == 0) {
					array[r] = array[l];
					array[l ++] = i;
				}
			}
			if ((digit = Integer.highestOneBit(use & digit - 1)) == 0) return;
			sort(array, left, l, use, digit);
			sort(array, l, right, use, digit);
		}
		public static void sort(final long[] array) {
			int l;
			long min = 0xFFFFFFFFFFFFFFFFL, max = 0;
			for (l = 0;l < array.length;++ l) {
				long i = array[l];
				min &= i;
				max |= i;
				if ((i & 0x8000000000000000L) == 0) break;
			}
			for (int r = l + 1;r < array.length;++ r) {
				long i = array[r];
				min &= i;
				max |= i;
				if ((i & 0x8000000000000000L) != 0) {
					array[r] = array[l];
					array[l ++] = i;
				}
			}
			long use = min ^ max, bit = Long.highestOneBit(use & 0x7FFFFFFFFFFFFFFFL);
			if (bit == 0) return;
			sort(array, 0, l, use, bit);
			sort(array, l, array.length, use, bit);
		}
		private static void sort(final long[] array, final int left, final int right, final long use, long digit) {
			if (right - left <= 96) {
				for (int i = left + 1, j;i < right;++ i) {
					long tmp = array[i], tmp2;
					for (j = i;j > left && (tmp2 = array[j - 1]) > tmp;-- j) array[j] = tmp2;
					array[j] = tmp;
				}
				return;
			}
			int l = left;
			while(l < right && (array[l] & digit) == 0) ++ l;
			for (int r = l + 1;r < right;++ r) {
				long i = array[r];
				if ((i & digit) == 0) {
					array[r] = array[l];
					array[l ++] = i;
				}
			}
			if ((digit = Long.highestOneBit(use & digit - 1)) == 0) return;
			sort(array, left, l, use, digit);
			sort(array, l, right, use, digit);
		}
	}

	public static class IntMath {
		public static int gcd(int a, int b) {
			while (a != 0) if ((b %= a) != 0) a %= b; else return a;
			return b;
		}
		public static int gcd(int... array) {
			int ret = array[0];
			for (int i = 1;i < array.length;++ i) ret = gcd(ret, array[i]);
			return ret;
		}
		public static long gcd(long a, long b) {
			while (a != 0) if ((b %= a) != 0) a %= b; else return a;
			return b;
		}
		public static long gcd(long... array) {
			long ret = array[0];
			for (int i = 1;i < array.length;++ i) ret = gcd(ret, array[i]);
			return ret;
		}
		public static long lcm(long a, long b) {
			return a / gcd(a, b) * b;
		}
		public static int pow(int a, int b) {
			int ans = 1;
			for (int mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul;
			return ans;
		}
		public static long powLong(long a, long b) {
			long ans = 1;
			for (long mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul;
			return ans;
		}
		public static int pow(int a, int b, int mod) {
			if (b < 0) b = b % (mod - 1) + mod - 1;
			long ans = 1;
			for (long mul = a;b > 0;b >>= 1, mul = mul * mul % mod) if ((b & 1) != 0) ans = ans * mul % mod;
			return (int)ans;
		}
		public static int floorsqrt(long n) {
			return (int)Math.sqrt(n + 0.1);
		}
		public static int ceilsqrt(long n) {
			return n <= 1 ? (int)n : (int)Math.sqrt(n - 0.1) + 1;
		}
	}
}
