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

public class Mo_LittleElephant {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		n = sc.nextInt();
		int m = sc.nextInt();
		
		sq = (int) Math.sqrt(n);
		
		a = new int[n];
		c = new int[n+1];
		
		for(int i=0; i<n; i++)
			a[i] = sc.nextInt();
		
		Query[] q = new Query[m];
		for(int i=0; i<m; i++)
			q[i] = new Query(sc.nextInt() - 1, sc.nextInt() - 1,i);
		
		Arrays.sort(q);
		int answers[] = new int[m];
		
		L = R = -1;
		
		for(int i=0; i<m; i++) {
			while(L < q[i].l)
			{
				remove(L++);
			}
			
			while(L > q[i].l)
			{
				add(--L);
			}
			
			while(R < q[i].r)
			{
				add(++R);
			}
			
			while(R > q[i].r)
			{
				remove(R--);
			}
			
			answers[q[i].i] = ans;
		}
		
		for(int ans : answers)
			out.println(ans);
		
		out.flush();
		out.close();
		
	}
	 
	static class Query implements Comparable<Query> {

		int l,r,i;
		
		public Query(int a, int b, int c)
		{
			l = a;
			r = b;
			i = c;
		}
		
		@Override
		public int compareTo(Query o) {
			int b1 = l / sq;
			int b2 = o.l / sq;
			
			if(b1 == b2)
				return r - o.r;
			
			return b1 - b2;
		}
	}
	
	static int ans;
	static int[] c;
	static int L;
	static int R;
	static int a[];
	static int n;
	static int sq;
	
	static void add(int i)
	{
		if(i == -1  || a[i] > n)
			return;
		Integer occ = c[a[i]];

		if(occ == a[i])
			ans--;
		c[a[i]]++;
		if(occ + 1 == a[i])
			ans++;
	}
	
	static void remove(int i) {
		if(i == -1 || a[i] > n)
			return;
		Integer occ = c[a[i]];

		if(occ == a[i])
			ans--;
		
		c[a[i]]--;
		
		if(occ - 1 == a[i])
			ans++;
	}
	
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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