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.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
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 {
        final int BLOCK_SIZE = 316;
        int n;
        int m;
        int result = 0;
        int[] a;
        int[] cnt = new int[(int) 1e5 + 1];

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

            n = in.nextInt();
            m = in.nextInt();
            a = in.nextIntArray(n);
            for (int i = 0; i < n; i++) {
                if (a[i] > (int) 1e5) {
                    a[i] = -1;
                }
            }

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

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


            Collections.sort(QS, (Triple<Integer, Integer, Integer> a, Triple<Integer, Integer, Integer> b) -> {
                int ll = a.getLeft() / BLOCK_SIZE;
                int rr = b.getLeft() / BLOCK_SIZE;
                int ret = Integer.valueOf(ll).compareTo(rr);
                if (ret == 0) {
                    return Integer.valueOf(a.getMiddle()).compareTo(b.getMiddle());
                }
                return ret;
            });

            int[] answers = new int[m];

            int left = QS.get(0).getMiddle();
            int right = left - 1;

            for (Triple<Integer, Integer, Integer> query : QS) {
                int curL = query.getLeft();
                int curR = query.getMiddle();

                while (right < curR && (right + 1) < a.length) {
                    right++;
                    add(a[right]);
                }

                while (right > curR && right >= 0) {
                    delete(a[right]);
                    right--;
                }

                while (left < curL && curL < a.length) {
                    delete(a[left]);
                    left++;
                }

                while (left > curL && (left - 1) >= 0) {
                    left--;
                    add(a[left]);
                }

                answers[query.getRight()] = result;
            }

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

        void add(int x) {
            if (x == -1) return;
            cnt[x]++;
            if (cnt[x] == x) result++;
            if (cnt[x] == x + 1) result--;
        }

        void delete(int x) {
            if (x == -1) return;
            cnt[x]--;
            if (cnt[x] == x) result++;
            if (cnt[x] == x - 1) result--;
        }

    }

    static class Triple<L extends Comparable<L>, M extends Comparable<M>, R extends Comparable<R>> implements Comparable<Triple<L, M, R>> {
        L left;
        M middle;
        R right;

        public Triple(L left, M middle, R right) {
            this.left = left;
            this.middle = middle;
            this.right = right;
        }

        public L getLeft() {
            return left;
        }

        public M getMiddle() {
            return middle;
        }

        public R getRight() {
            return right;
        }


        public String toString() {
            return String.format("(%s,%s,%s)", left, middle, right);
        }


        public int compareTo(Triple<L, M, R> o) {
            int ret = left.compareTo(o.left);
            if (ret == 0) ret = middle.compareTo(o.middle);
            if (ret == 0) ret = right.compareTo(o.right);
            return ret;
        }

        public static <L extends Comparable<L>, M extends Comparable<M>, R extends Comparable<R>> Triple<L, M, R> of(L left, M middle, R right) {
            return new Triple<>(left, middle, right);
        }

    }

    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;
        }

    }
}

