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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class LittleElephandAndArray {

	static class Solver {

		class Query implements Comparable<Query> {

			int L, R, rt, id;

			Query(int l, int r, int i) {
				L = l;
				R = r;
				rt = L / size;
				id = i;
			}

			public int compareTo(Query q) {
				if (q.rt == rt)
					return R - q.R;
				return rt - q.rt;
			}

		}

		int N, Q, size, a[], f[], ans[];
		Query[] queries;

		void solve(FastScanner s, PrintWriter out) {
			N = s.nextInt();
			size = (int) (Math.sqrt(N) + 1);
			Q = s.nextInt();
			a = s.nextIntArray(N);
			f = new int[N + 1];
			queries = new Query[Q];
			ans = new int[Q];
			for (int i = 0; i < Q; i++)
				queries[i] = new Query(s.nextInt() - 1, s.nextInt() - 1, i);
			Arrays.sort(queries);
			int l = 0, r = 0, ct = 0;
			if (a[0] <= N)
				f[a[0]]++;
			if (a[0] == 1)
				ct++;
			for (Query q : queries) {
				int ll = q.L, rr = q.R;
				while (l < ll) {
					if (a[l] <= N) {
						if (f[a[l]] == a[l])
							ct--;
						f[a[l]]--;
						if (f[a[l]] == a[l])
							ct++;
					}
					l++;
				}
				while (l > ll) {
					l--;
					if (a[l] <= N) {
						if (f[a[l]] == a[l])
							ct--;
						f[a[l]]++;
						if (f[a[l]] == a[l])
							ct++;
					}
				}
				while (r < rr) {
					r++;
					if (a[r] <= N) {
						if (f[a[r]] == a[r])
							ct--;
						f[a[r]]++;
						if (f[a[r]] == a[r])
							ct++;
					}
				}
				while (r > rr) {
					if (a[r] <= N) {
						if (f[a[r]] == a[r])
							ct--;
						f[a[r]]--;
						if (f[a[r]] == a[r])
							ct++;
					}
					r--;
				}
				ans[q.id] = ct;
			}

			for (int i : ans)
				out.println(i);
		}

	}

	public static void main(String[] args) {
		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		Solver solver = new Solver();
		solver.solve(s, out);

		out.close();
	}

	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		public long nextLong() {
			return Long.parseLong(next());
		}

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

		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		// Jacob Garbage

		public int[] nextIntArray(int N) {
			int[] ret = new int[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextInt();
			return ret;
		}

		public long[] nextLongArray(int N) {
			long[] ret = new long[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextLong();
			return ret;
		}

		public int[][] next2DIntArray(int N, int M) {
			int[][] ret = new int[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextIntArray(M);
			return ret;
		}

		public double[] nextDoubleArray(int N) {
			double[] ret = new double[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDouble();
			return ret;
		}

		public double[][] next2DDoubleArray(int N, int M) {
			double[][] ret = new double[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDoubleArray(M);
			return ret;
		}

	}

}
