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 static java.lang.Math.*; 

import java.io.*; 
import java.util.*; 

public class Template {
	BufferedReader in; 
	PrintWriter out;
	StringTokenizer st; 

	String next() {
		while (st==null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(in.readLine());
			} catch (Exception e) {}
		}
		return st.nextToken(); 
	}

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

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

	double nextDouble() {
		return Double.parseDouble(next());
	}
	
	class Point implements Comparable<Point> {
		int x, y; 
		public Point(int x, int y) {
			this.x=x; 
			this.y=y; 
		}

		public boolean equals(Object o) {
			Point other = (Point)o; 
			return (x == other.x && y == other.y);
		}

		public int hashCode() {
			return x * 256 + y; 
		}

		public int compareTo(Point o) {
			if (x!=o.x) return sign(x-o.x); else return sign(y - o.y);
		}

		public int sign(int x) {
			if (x==0) return 0; 
			if (x<0) return -1; 
			return 1; 
		}
		              
		public String toString() {
			return x + " " + y; 
		}
	}

	int[] s = new int[1010001]; 

	void update(int x, int val) {
		while (x <= 1000000) {
			s[x] += val; 
			x = x | (x + 1); 
		}
	}
	
	int get(int x) {
		int ret = 0; 
		while (x>=0) {
			ret += s[x]; 
			x = (x & (x + 1)) - 1; 
		}
		return ret; 
	}

	int get(int l, int r) {
		return get(r) - get(l-1); 
	}

	public void run() throws Exception {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
			int n = nextInt(); 
			int m = nextInt(); 
			int[] a = new int[n]; 
			for (int i=0; i<n; i++) a[i] = nextInt(); 

			ArrayList<Point>[] q = new ArrayList[n+12]; 
			ArrayList<Integer>[] w = new ArrayList[n+12];

			for (int i=0; i<=n; i++) {
				q[i] = new ArrayList<Point>(); 
				w[i] = new ArrayList<Integer>(); 
			}

			for (int i=0; i<m; i++) {
				int l = nextInt() - 1; 
				int r = nextInt() - 1; 
				q[r].add(new Point(l, i)); 
			}

			int[] ans = new int[m]; 

			for (int i=0; i<n; i++) {
				if (a[i] <= n) {
					w[a[i]].add(i);
					int len = w[a[i]].size(); 
					if (w[a[i]].size() > a[i]) {
						update(w[a[i]].get(len - a[i] - 1), -2);
					}

					if (w[a[i]].size() >= a[i]) {
						update(w[a[i]].get(len - a[i]), 1); 
					}
					if (w[a[i]].size() > a[i] + 1) {
						update(w[a[i]].get(len - a[i] - 2), 1); 
					}
				}

				for (Point p : q[i]) {
					ans[p.y] = get(p.x, i); 
				}
			}

			for (int i=0; i<m; i++) out.println(ans[i]); 

		Long end = System.currentTimeMillis();
		out.close(); 
	}

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