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.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskB {
        static int[] hash;
        static int ct = 0;
        static int[] a;
        static int BLOCK_SIZE;
        static int MAXVALUE;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            BLOCK_SIZE = (int) (Math.sqrt(n) + 1);
            a = in.nextIntArray(n);
            for (int i = 0; i < n; ++i) MAXVALUE = Math.max(MAXVALUE, a[i]);
            MAXVALUE = Math.min(MAXVALUE, n);
            hash = new int[MAXVALUE + 1];
            TaskB.Query[] q = new TaskB.Query[m];
            for (int i = 0; i < m; ++i) {
                q[i] = new TaskB.Query(in.nextInt() - 1, in.nextInt() - 1, i);
            }
            Arrays.sort(q);
            int[] ans = new int[m];
            int left = 0;
            int right = -1;
            for (int i = 0; i < m; ++i) {
                int L = q[i].L;
                int R = q[i].R;
                while (left < L) remove(a[left++]);
                while (left > L) add(a[--left]);
                while (right < R) add(a[++right]);
                while (right > R) remove(a[right--]);
                ans[q[i].idx] = ct;
            }
            for (int aa : ans) out.println(aa);
        }

        public static void add(int val) {
            if (val > MAXVALUE) return;
            if (hash[val] == val) --ct;
            ++hash[val];
            if (hash[val] == val) ++ct;
        }

        public static void remove(int val) {
            if (val > MAXVALUE) return;
            if (hash[val] == val) --ct;
            --hash[val];
            if (hash[val] == val) ++ct;
        }

        static class Query implements Comparable<TaskB.Query> {
            int L;
            int R;
            int block;
            int idx;

            public Query(int l, int r, int i) {
                L = l;
                R = r;
                idx = i;
                block = L / BLOCK_SIZE;
            }

            public int compareTo(TaskB.Query o) {
                if (block != o.block) return block - o.block;
                return R - o.R;
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

