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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class C {
    static class Query {
        int l, r, idx;
        Query (int ll, int rr, int ii) {l = ll; r = rr; idx = ii;}
    }
    static int n, arr[], SQRT = 900;
    static int moL = 0, moR = -1;
    static HashMap<Integer, Integer> cnt = new HashMap<>();

    static void rightR (int L, int R) {
        // moR < R
        while (moR < R) {
            moR++;
            if (arr[moR] > n) continue;
            Integer was = cnt.get(arr[moR]);
            if (was == arr[moR]) resSoFar--;
            else if (was == arr[moR] - 1) resSoFar++;
            if (was == null) cnt.put(arr[moR], 1);
            else cnt.put(arr[moR], was.intValue() + 1);
        }
    }

    static void leftL (int L, int R) {
        // moL > L
        while (moL > L) {
            moL--;
            if (arr[moL] > n) continue;
            Integer was = cnt.get(arr[moL]);
            if (was == arr[moL]) resSoFar--;
            else if (was == arr[moL] - 1) resSoFar++;
            if (was == null) cnt.put(arr[moL], 1);
            else cnt.put(arr[moL], was.intValue() + 1);
        }
    }

    static void rightL (int L, int R) {
        // moR > R
        while (moR > R) {
            if (arr[moR] > n) continue;
            Integer was = cnt.get(arr[moR]);
            if (was == arr[moR]) resSoFar--;
            else if (was == arr[moR] + 1) resSoFar++;
            if (was == 1) cnt.put(arr[moR], 0);
            else cnt.put(arr[moR], was.intValue() - 1);
            moR--;
        }
    }

    static void leftR (int L, int R) {
        // moL < L
        while (moL < L) {
            if (arr[moL] > n) continue;
            Integer was = cnt.get(arr[moL]);
            if (was == arr[moL]) resSoFar--;
            else if (was == arr[moL] + 1) resSoFar++;
            if (was == 1) cnt.put(arr[moL], 0);
            else cnt.put(arr[moL], was.intValue() - 1);
            moL++;
        }
    }
    static int resSoFar = 0;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt();
        int q = sc.nextInt();
        arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = sc.nextInt();

        Query[] queries = new Query[q];
        for (int i = 0; i < q; i++)
            queries[i] = new Query(sc.nextInt() - 1, sc.nextInt() - 1, i);
        Arrays.sort(queries, new Comparator<Query>() {
            @Override
            public int compare(Query q1, Query q2) {
                if (q1.l / SQRT != q2.l / SQRT) return q1.l / SQRT - q2.l / SQRT;
                return q1.r - q2.r;
            }
        });

        for (int i = 1; i <= n; i++)
            cnt.put(i, 0);
        int[] res = new int[q];
        for (int i = 0; i < q; i++) {
            int L = queries[i].l, R = queries[i].r;
            rightR(L, R);
            leftL(L, R);
            leftR(L, R);
            rightL(L, R);
            res[queries[i].idx] = resSoFar;
        }

        for (int i = 0; i < q; i++) {
            out.println(res[i]);
        }
        out.println();
        out.flush();
        out.close();
    }


























    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}