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.*;
import java.util.function.Consumer;

public class Main {
    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();


//        stringBuilder.append("13 3\n" +
//                "1 2\n" +
//                "3 2\n" +
//                "4 2\n" +
//                "5 2\n" +
//                "3 6\n" +
//                "10 6\n" +
//                "6 7\n" +
//                "6 13\n" +
//                "5 8\n" +
//                "5 9\n" +
//                "9 11\n" +
//                "11 12");
        // 2 - 1 - 3
        //     4
        // 1 1 2 2 3
        // 1 1 2 2
        // 1 1 2
        // 1 1
        // 1
        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }


        out = new PrintWriter(new OutputStreamWriter(System.out));
        initData();
        solve();
        out.flush();
    }


    private static void initData() {
    }

    private static void solve() throws IOException {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int tm = (int) Math.sqrt(n);
        int[] data = sc.na(n);
        int[][] q = new int[k][4];
        for (int i = 0; i < k; i++) {
            q[i][0] = sc.nextInt() - 1;
            q[i][1] = sc.nextInt() - 1;
            q[i][2] = i;
            q[i][3] = (q[i][1] - q[i][0] + 1) / tm;
        }


        Arrays.sort(q, Comparator.<int[]>comparingInt(t -> t[3]).thenComparing(t -> t[3] % 2 == 0 ? t[1] : -t[1]));
        int m0 = 0;
        int m1 = -1;
        long cur = 0;
        long[] res = new long[k];
        int[] cc = new int[100001];
        for (int[] q1 : q) {
            while (q1[1] != m1) {
                if (q1[1] > m1) {
                    m1++;
                    if (data[m1] < cc.length) {
                        cc[data[m1]]++;
                        if (data[m1] == cc[data[m1]]) {
                            cur++;
                        }
                        if (data[m1] + 1 == cc[data[m1]]) {
                            cur--;
                        }
                    }

                } else {
                    if (data[m1] < cc.length) {
                        if (data[m1] == cc[data[m1]]) {
                            cur--;
                        }
                        if (data[m1] + 1 == cc[data[m1]]) {
                            cur++;
                        }
                        cc[data[m1]]--;
                    }
                    m1--;
                }
            }
            while (q1[0] != m0) {
                if (q1[0] > m0) {
                    if (data[m0] < cc.length) {
                        if (data[m0] == cc[data[m0]]) {
                            cur--;
                        }
                        if (data[m0] == cc[data[m0]] - 1) {
                            cur++;
                        }
                        cc[data[m0]]--;
                    }
                    m0++;
                } else {
                    m0--;
                    if (data[m0] < cc.length) {
                        cc[data[m0]]++;
                        if (data[m0] == cc[data[m0]]) {
                            cur++;
                        }
                        if (data[m0] == cc[data[m0]] - 1) {
                            cur--;
                        }
                    }

                }
            }
            res[q1[2]] = cur;
        }
        for (long x : res) {
            out.println(x);
        }
    }


    private static int[] dfs(int start, int[][] neig, Consumer<int[]> onAdd, Consumer<int[]> onRemove) {
        int[][] vis0 = new int[neig.length * 2][];
        int l = 0;
        vis0[l++] = new int[]{start, 0, -1, 0, 0};

        boolean[] vis = new boolean[neig.length];
        vis[start] = true;
        int[] level = new int[neig.length];
        while (l > 0) {
            int[] ppr = vis0[--l];
            if (ppr[1] == 1) {
                onRemove.accept(ppr);
                continue;
            }
            ppr[1] = 1;
            int i = ppr[0];
            vis0[l++] = ppr;
            onAdd.accept(ppr);
            for (int kk : neig[i]) {
                if (!vis[kk]) {
                    vis[kk] = true;
                    level[kk] = level[i] + 1;
                    vis0[l++] = new int[]{kk, 0, i, level[kk]};
                }
            }
        }
        return level;
    }

    private static int[][] tr(int n) {
        int[][] x = new int[2][n - 1];
        for (int i = 0; i < n - 1; i++) {
            x[0][i] = sc.nextInt() - 1;
            x[1][i] = sc.nextInt() - 1;
        }
        return pn(x, n);
    }

    private static int[][] pn(int[][] x, int n) {
        int[] ct = new int[n];
        int[][] res = new int[n][];
        for (int v : x[0]) {
            ct[v]++;
        }
        for (int v : x[1]) {
            ct[v]++;
        }
        for (int l = 0; l < n; l++) {
            res[l] = new int[ct[l]];
        }
        for (int i = 0; i < x[0].length; i++) {
            res[x[0][i]][--ct[x[0][i]]] = x[1][i];
            res[x[1][i]][--ct[x[1][i]]] = x[0][i];
        }
        return res;
    }


    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

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

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


}