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.util.*;
public class LittleElephantAndArray {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i ++)
			a[i] = in.nextInt();
		Mo mo = new Mo(a);
		for(int i = 0; i < m; i ++)
			mo.addQuery(in.nextInt() - 1, in.nextInt() - 1, i);
		
		ArrayList<Integer> ans = mo.getAns();
		for(int e: ans)
			System.out.println(e);
	}
	static class Mo
	{
		int[] a;
		int n, sqrtn;
		ArrayList<Query> queries;
		Mo(int[] a)
		{
			n = a.length;
			sqrtn = (int)Math.sqrt(n);
			this.a = Arrays.copyOf(a,  n);
			queries = new ArrayList<Query>();
		}
		void addQuery(int a, int b, int i)
		{
			queries.add(new Query(a, b,i));
		}
		
		ArrayList<Integer> getAns()
		{
			ArrayList<Answer> temp = new ArrayList<Answer>();
			ArrayList<Integer> ans = new ArrayList<Integer>();
			Collections.sort(queries);
			
			//compute answer here
			int[] f = new int[n + 1];
			if(a[0] <= n)
				f[a[0]] = 1;
			int p1 = 0;
			int p2 = 0;
			int cans = a[0] == 1 ? 1 : 0;
			for(Query q: queries)
			{				
				while(p1 < q.a)
				{
					if(a[p1] > n)
					{
						p1++;
						continue;
					}
					f[a[p1]]--;
					if(f[a[p1]] == a[p1])
						cans++;
					if(f[a[p1]] == a[p1] - 1)
						cans--;
					p1++;
				}
				while(p1 > q.a)
				{
					p1--;
					if(a[p1] > n)
						continue;
					f[a[p1]]++;
					if(f[a[p1]] == a[p1])
						cans++;
					if(f[a[p1]] == a[p1] + 1)
						cans--;
				}
				while(p2 < q.b)
				{
					p2++;
					if(a[p2] > n)
						continue;
					f[a[p2]]++;
					if(f[a[p2]] == a[p2])
						cans++;
					if(f[a[p2]] == a[p2] + 1)
						cans--;
				}
				while(p2 > q.b)
				{
					if(a[p2] > n)
					{
						p2--;
						continue;
					}
					f[a[p2]]--;
					if(f[a[p2]] == a[p2])
						cans++;
					if(f[a[p2]] == a[p2] - 1)
						cans--;
					p2--;
				}
				temp.add(new Answer(q.i, cans));
			}
			
			Collections.sort(temp);
			for(int i = 0; i < temp.size(); i ++)
				ans.add(temp.get(i).v);
			return ans;
		}
		class Answer implements Comparable<Answer>
		{
			int i;
			int v;
			Answer(int i, int v)
			{
				this.i = i;
				this.v = v;
			}
			public int compareTo(Answer a)
			{
				return i - a.i;
			}
		}
		class Query implements Comparable<Query>
		{
			int a, b, i, block;
			Query(int a, int b, int i)
			{
				this.a = a;
				this.b = b;
				this.i=i;
				block = a/sqrtn;
			}
			public int compareTo(Query q) 
			{
				return block == q.block ? b-q.b : block - q.block;
			}
			public String toString()
			{
				return "(" + a + ", " + b + ", " + i + ")";
			}
		}
	}
}
