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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ATailouloute
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        QuickScanner in = new QuickScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        int n;
        int m;
        int[] a;
        int[] cnt = new int[(int) 1e5 + 1];
        int[] pref;

        public void solve(int testNumber, QuickScanner in, PrintWriter out) {

            n = in.nextInt();
            m = in.nextInt();
            a = in.nextIntArray(n);
            pref = new int[n];
            for (int i = 0; i < n; i++) {
                if (a[i] <= n) {
                    cnt[a[i]]++;
                }
            }

            List<Integer> G = new ArrayList<>();

            for (int i = 1; i <= n; i++) {
                if (cnt[i] >= i) {
                    G.add(i);
                }
            }

            List<Pair<Integer, Integer>> QS = new ArrayList<>();

            for (int i = 0; i < m; i++) {
                int left = in.nextInt() - 1;
                int right = in.nextInt() - 1;
                QS.add(Pair.of(left, right));
            }

            int[] answers = new int[m];

            for (int good : G) {
                Arrays.fill(pref, 0);
                for (int i = 0; i < n; i++) {
                    if (a[i] == good) {
                        pref[i] = 1;
                    }
                    if (i > 0) {
                        pref[i] += pref[i - 1];
                    }
                }
                for (int i = 0; i < m; i++) {
                    Pair<Integer, Integer> query = QS.get(i);
                    int nb = pref[query.getSecond()];
                    if (query.getFirst() > 0) {
                        nb -= pref[query.getFirst() - 1];
                    }
                    if (nb == good) {
                        answers[i]++;
                    }
                }
            }

            for (int i = 0; i < m; i++) {
                out.println(answers[i]);
            }
        }

    }

    static class Pair<F extends Comparable<F>, S extends Comparable<S>> implements Comparable<Pair<F, S>> {
        F first;
        S second;

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }

        public F getFirst() {
            return first;
        }

        public S getSecond() {
            return second;
        }

        public int compareTo(Pair<F, S> o) {
            int ret = first.compareTo(o.first);
            if (ret == 0)
                ret = second.compareTo(o.second);
            return ret;
        }


        public String toString() {
            return String.format("(%s,%s)", first.toString(), second.toString());
        }

        public static <F extends Comparable<F>, S extends Comparable<S>> Pair<F, S> of(F first, S second) {
            return new Pair<>(first, second);
        }

    }

    static class QuickScanner {
        BufferedReader br;
        StringTokenizer st;
        InputStream is;

        public QuickScanner(InputStream stream) {
            is = stream;
            br = new BufferedReader(new InputStreamReader(stream), 32768);
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

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

    }
}

