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 final class little_mo
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static int[] cnt,a;
	static int maxn=(int)1e5+3,block,ans=0;
	
	static void add(int curr)
	{
		if(curr<maxn)
		{
			int prev=cnt[curr];cnt[curr]++;
			if(cnt[curr]==curr)
			{
				ans++;
			}
			else if(prev==curr)
			{
				ans--;
			}
		}
	}
	
	static void del(int curr)
	{
		if(curr<maxn)
		{
			int prev=cnt[curr];cnt[curr]--;
			if(cnt[curr]==curr)
			{
				ans++;
			}
			else if(prev==curr)
			{
				ans--;
			}
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),q=sc.nextInt();a=new int[n];block=(int)Math.sqrt(n);cnt=new int[maxn];
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
		}
		Node[] arr=new Node[q];
		for(int i=0;i<q;i++)
		{
			arr[i]=new Node(i,sc.nextInt()-1,sc.nextInt()-1);
		}
		Arrays.sort(arr,new Comparator<Node>()
		{
			public int compare(Node x1,Node x2)					
			{
				if(x1.l/block==x2.l/block)
				{
					return x1.r-x2.r;
				}
				return (x1.l/block)-(x2.l/block);
			}
		});
		int l=0,r=0;ans=0;int[] res=new int[q];
		for(int i=0;i<q;i++)
		{
			while(l>arr[i].l)
			{
				add(a[l-1]);l--;
			}
			while(r<=arr[i].r)
			{
				add(a[r]);r++;
			}
			while(l<arr[i].l)
			{
				del(a[l]);l++;
			}
			while(r>arr[i].r+1)
			{
				del(a[r-1]);r--;
			}
			res[arr[i].idx]=ans;
		}
		for(int i=0;i<q;i++)
		{
			out.println(res[i]);
		}
		out.close();
    }
}
class Node
{
	int idx,l,r;
	public Node(int idx,int l,int r)
	{
		this.idx=idx;this.l=l;this.r=r;
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}