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.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC)throws Exception{
        int n = ni(), m = ni();
        int[] a = new int[n];
        int[] f = new int[n+1];
        int ans = 0;
        int[] qans = new int[m];
        for(int i = 0; i< n; i++){
            long x = nl();
            if(x > n)a[i] = 0;
            else a[i] = (int)x;
        }
        int[][] qu = new int[m][];
        for(int i = 0; i< m; i++)qu[i] = new int[]{ni()-1, ni()-1, i};
        int B = (int)Math.sqrt(n+0.5);
        Arrays.sort(qu, (int[] i1, int[] i2) -> {
            int b1 = i1[1]/B, b2 = i2[1]/B;
            if(b1 != b2)return Integer.compare(b1, b2);
            return ((b1&1)==1?1:-1)*Integer.compare(i1[0], i2[0]);
        });
        int l = 0, r = -1;
        for(int i = 0; i< m; i++){
            while(r < qu[i][1]){
                r++;
                if(a[r] != 0){
                    if(f[a[r]] == a[r])ans--;
                    f[a[r]]++;
                    if(f[a[r]] == a[r])ans++;
                }
//                pn(l+" "+r+" " +ans);
            }
            while(l > qu[i][0]){
                l--;
                if(a[l] != 0){
                    if(f[a[l]] == a[l])ans--;
                    f[a[l]]++;
                    if(f[a[l]] == a[l])ans++;
                }
//                pn(l+" "+r+" " +ans);
            }
            while(r > qu[i][1]){
                if(a[r] != 0){
                    if(f[a[r]] == a[r])ans--;
                    f[a[r]]--;
                    if(f[a[r]] == a[r])ans++;
                }
                r--;
//                pn(l+" "+r+" " +ans);
            }
            while(l < qu[i][0]){
                if(a[l] != 0){
                    if(f[a[l]] == a[l])ans--;
                    f[a[l]]--;
                    if(f[a[l]] == a[l])ans++;
                }
                l++;
//                pn(l+" "+r+" " +ans);
            }
            qans[qu[i][2]] = ans;
        }
        for(int i:qans)pn(i);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e18, mod = (long)1e8+7;
    final int INF = (int)1e9, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        if(fileIO){
            in = new FastReader("input.txt");
            out = new PrintWriter("output.txt");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}
 
    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }
 
        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }
 
        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}