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.text.DecimalFormat;
import java.util.*;
import java.awt.Point;
import java.math.BigInteger;

public class Newbie {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.sol();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

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

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

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

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static class extra {

        static long fastexpo(long x, long y) {
            long res = 1;
            while (y > 0) {
                if ((y & 1) == 1) {
                    res *= x;
                }
                y = y >> 1;
                x = x * x;
            }
            return res;
        }

        static long lfastexpo(long x, long y, long p) {
            long res = 1;
            x = x % p;
            while (y > 0) {
                if ((y & 1) == 1) {
                    res = (res * x) % p;
                }
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        extra e = new extra();
        long mod = (long) (1e9 + 7);
        int s;

        class q implements Comparable<q> {
            int l;
            int r;
            int i;

            q(int a, int b, int c) {
                l = a;
                r = b;
                i = c;
            }

            public int compareTo(q x) {
                if ((this.l / s) != x.l / s)
                    return this.l - x.l;
                return ((this.l / s) % 2 != 0) ? (this.r - x.r) : (x.r - this.r);
            }
        }

        int map[], n, ans;

        void add(int a) {
            if (a > n)
                return;
            if (map[a] == a)
                ans--;
            map[a]++;
            if (map[a] == a)
                ans++;
        }

        void remove(int a) {
            if (a > n)
                return;
            if (map[a] == a)
                ans--;
            map[a]--;
            if (map[a] == a)
                ans++;
        }

        void sol() throws IOException {
            n = sc.ni();
            map = new int[n + 1];
            s = (int) Math.ceil(Math.sqrt(n));
            int m = sc.ni();
            int a[] = sc.na(n);
            q b[] = new q[m];
            for (int i = 0; i < m; i++) {
                int l = sc.ni() - 1;
                int r = sc.ni() - 1;
                b[i] = new q(l, r, i);
            }
            Arrays.sort(b);
            int cl = 0, cr = -1;
            int ans[] = new int[m];
            for (q h : b) {
                int l = h.l;
                int r = h.r;
                while (cl > l) {
                    cl--;
                    add(a[cl]);
                }
                while (cr < r) {
                    cr++;
                    add(a[cr]);
                }
                while (cl < l) {
                    remove(a[cl]);
                    cl++;
                }
                while (cr > r) {
                    remove(a[cr]);
                    cr--;
                }
                ans[h.i] = this.ans;
            }
            for (int h : ans)
                out.println(h);
        }
    }
}

