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.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BLittleElephantAndArray solver = new BLittleElephantAndArray();
        solver.solve(1, in, out);
        out.close();
    }

    static class BLittleElephantAndArray {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int q = in.scanInt();
            int[] ar = new int[n + 1];
            for (int i = 1; i <= n; i++) ar[i] = in.scanInt();
            int[][] queries = new int[q][2];
            ArrayList<Integer>[] positions = new ArrayList[n + 1];
            for (int i = 0; i <= n; i++) positions[i] = new ArrayList<>();
            ArrayList<int[]>[] query = new ArrayList[n + 1];
            for (int i = 0; i <= n; i++) query[i] = new ArrayList<>();
            for (int i = 0; i < q; i++) {
                queries[i][0] = in.scanInt();
                queries[i][1] = in.scanInt();
                query[queries[i][1]].add(new int[]{i, queries[i][0]});
            }

            BIT ans = new BIT(n + 2);
            int[] answer = new int[q];
            for (int i = 1; i <= n; i++) {
                if (ar[i] <= n) {
                    positions[ar[i]].add(i);
                    if (positions[ar[i]].size() > ar[i]) {
                        ans.update(positions[ar[i]].get(positions[ar[i]].size() - ar[i]), 1);
                        ans.update(positions[ar[i]].get(positions[ar[i]].size() - ar[i] - 1), -2);
                        if (positions[ar[i]].size() > ar[i] + 1)
                            ans.update(positions[ar[i]].get(positions[ar[i]].size() - ar[i] - 2), 1);
                    } else if (positions[ar[i]].size() == ar[i]) {
                        ans.update(positions[ar[i]].get(positions[ar[i]].size() - ar[i]), 1);
                    }
                }

                for (int[] queryPositions : query[i]) {
                    answer[queryPositions[0]] = ans.query(i) - ans.query(queryPositions[1] - 1);
                }
            }
            for (int i : answer) out.println(i);
        }

    }

    static class BIT {
        int[] BIT;
        int n;

        public BIT(int n) {
            this.BIT = new int[n + 1];
            this.n = n;
        }

        public void update(int x, int delta) {
            for (; x <= n; x += x & -x)
                BIT[x] += delta;
        }

        public int query(int x) {
            int sum = 0;
            for (; x > 0; x -= x & -x)
                sum += BIT[x];
            return sum;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

