The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. 

Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.

Help the Little Elephant to count the answers to all queries.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).

Output

In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.

Examples

Input

7 2
3 1 2 2 3 3 7
1 7
3 4


Output

3
1
import java.io.*;
import java.util.*;

public class Mainn {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	class node implements Comparable<node> {
		int l, r, i;

		node(int a, int b, int c) {
			l = a;
			r = b;
			i = c;
		}

		public int compareTo(node o) {
			return this.l / blockSize == o.l / blockSize ? this.r - o.r : this.l / blockSize - o.l / blockSize;
		}
	}

	int blockSize;

	void solve() {
		int n = scn.nextInt(), q = scn.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}
		blockSize = (int) Math.sqrt(n);

		node[] query = new node[q];
		for (int i = 0; i < q; i++) {
			query[i] = new node(scn.nextInt() - 1, scn.nextInt() - 1, i);
		}
		Arrays.sort(query);

		int[] cnt = new int[n + 1];

		int[] ans = new int[q];
		int curL = 0, curR = -1;
		for (int i = 0, x = 0; i < q; i++) {
			while (curR < query[i].r) {
				curR++;
				if (arr[curR] <= n) {
					if (cnt[arr[curR]] == arr[curR]) {
						x--;
					}
					cnt[arr[curR]]++;
					if (cnt[arr[curR]] == arr[curR]) {
						x++;
					}
				}
			}
			while (curL > query[i].l) {
				curL--;
				if (arr[curL] <= n) {
					if (cnt[arr[curL]] == arr[curL]) {
						x--;
					}
					cnt[arr[curL]]++;
					if (cnt[arr[curL]] == arr[curL]) {
						x++;
					}
				}
			}

			while (curL < query[i].l) {
				if (arr[curL] <= n) {
					if (cnt[arr[curL]] == arr[curL]) {
						x--;
					}
					cnt[arr[curL]]--;
					if (cnt[arr[curL]] == arr[curL]) {
						x++;
					}
				}
				curL++;
			}
			while (curR > query[i].r) {
				if (arr[curR] <= n) {
					if (cnt[arr[curR]] == arr[curR]) {
						x--;
					}
					cnt[arr[curR]]--;
					if (cnt[arr[curR]] == arr[curR]) {
						x++;
					}
				}
				curR--;
			}
			ans[query[i].i] = x;
		}

		for (int x : ans) {
			out.println(x);
		}
	}

	void run() throws Exception {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) throws Exception {
		new Mainn().run();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());

		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}
	}
}