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.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

    public static int[] M;
    public static int n;
    public static void add(int x) {
        if(x<=n)
        M[x]++;
    }
    public static void remove(int x) {
        if(x<=n)
        M[x]--;
    }
    public static int get(int x) {
        if(x>n) return 0;
        return M[x];
    }
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        InputReader in = new InputReader(inputStream);
        
         n=in.nextInt();int q=in.nextInt();
         M=new int[n+10];
        int[] a=in.nextArray(n);
        int[][] Q=new int[q][3];
        for(int i=0;i<q;i++){
            Q[i][0]=in.nextInt()-1;
            Q[i][1]=in.nextInt()-1;
            Q[i][2]=i;
        }
        int BLOCK_SIZE=(int)Math.sqrt(n);
        
        Arrays.sort(Q, new Comparator<int[]>(){
            @Override
            public int compare(int[] t, int[] t1) {// das ist nicht eine aenliche coke
                int x=t[0]/BLOCK_SIZE;
                int y=t1[0]/BLOCK_SIZE;
                if(x==y) return t[1]-t1[1];
                else return t[0]-t1[0];
            }
        });
        int[] answer=new int[q];
        int L=Q[0][0],R=Q[0][1];
        int ans=0;
        for(int i=Q[0][0];i<=Q[0][1];i++){
            if(get(a[i])==a[i]-1)ans++;
            else if(get(a[i])==a[i])ans--;
            add(a[i]);
        }
        answer[Q[0][2]]=ans;
        for(int i=1;i<q;i++){
            while(L<Q[i][0]){
                if(get(a[L])==a[L])ans--;
                else if(get(a[L])==a[L]+1)ans++;
                remove(a[L]);
                L++;
            }
            while(Q[i][0]<L){
                if(get(a[L-1])==a[L-1]-1)ans++;
                else if(get(a[L-1])==a[L-1])ans--;
                add(a[L-1]);
                L--;
            }
            while(R<Q[i][1]){
                if(get(a[R+1])==a[R+1]-1)ans++;
                else if(get(a[R+1])==a[R+1])ans--;
                add(a[R+1]);
                R++;
            }
            while(R>Q[i][1]){
                if(get(a[R])==a[R])ans--;
                else if(get(a[R])==a[R]+1)ans++;
                remove(a[R]);
                R--;
            }
            answer[Q[i][2]]=ans;
        }
        for(int i=0;i<q;i++)
            out.println(answer[i]);
        out.close();
    }

    static class InputReader {

        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 32624);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public double[] nextArrayd(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextDouble();
            }
            return a;
        }

        private BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public void printAr(int[] a) {
            System.out.print("[");
            for (long x : a) {
                System.out.print(x + ",");
            }
            System.out.print("]");
        }
    }

}