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.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class CFD {

    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    public static void main(String[] args) {
        CFD t = new CFD();
        t.init();
    }

    void run() throws Exception {
        int n = Int();
        int m = Int();
        int[] array = IntArray(n);

        TreeMap<Integer, List<Integer>> indices = new TreeMap<Integer, List<Integer>>();

        for (int i = 0; i < array.length; i++) {
            List<Integer> list = indices.get(array[i]);
            if (list == null) {
                list = new ArrayList<Integer>();
                indices.put(array[i], list);
            }
            list.add(i);
        }

        List<Interval> intervals = new ArrayList<Interval>();

        for (Integer x : indices.keySet()) {
            List<Integer> list = indices.get(x);

            for (int i = 0; i < list.size() - x + 1; i++) {
                intervals.add(new Interval(list.get(i), list.get(i + x - 1), i == 0 ? Integer.MIN_VALUE : list.get(i - 1), i + x - 1 == list.size() - 1 ? Integer.MAX_VALUE : list.get(i + x), x));
            }
        }

        Collections.sort(intervals, new Comparator<Interval>() {
            @Override
            public int compare(Interval o1, Interval o2) {
                return new Integer(o1.lower).compareTo(o2.lower);
            }
        });

        for (int i = 0; i < m; i++) {
            int a = Int() - 1;
            int b = Int() - 1;

            int num = 0;
            for (int j = 0; j < intervals.size(); j++) {
                Interval inter = intervals.get(j);
                if (inter.icContainedIn(a, b)) {
                    num++;
                }
                if (inter.lower > b) {
                    continue;
                }
            }
            PrintLn(num);
        }
    }

    class Interval {
        int lower, upper;
        int minLower, maxUpper;
        int num;

        public Interval(int lower, int upper, int minLower, int maxUpper, int num) {
            super();
            this.lower = lower;
            this.upper = upper;
            this.minLower = minLower;
            this.maxUpper = maxUpper;
            this.num = num;
        }

        boolean icContainedIn(int a, int b) {
            return lower >= a && upper <= b && minLower < a && maxUpper > b;
        }
    }

    void init() {
        try {
            Locale.setDefault(Locale.US);
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            run();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

    String String() throws Exception {
        return next();
    }

    int Int() throws Exception {
        return Integer.parseInt(next());
    }

    int[] IntArray(int n) throws Exception {
        int[] array = new int[n];
        for (int i = 0; i < array.length; i++) {
            array[i] = Int();
        }
        return array;
    }

    void PrintLn(Object line) {
        out.println(line);
    }

    void PrintArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            out.print(array[i] + " ");
        }
        out.println();
    }

}
