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.util.*;
//
//public class Main {
//    public static void main(String[] args) throws IOException {
//        ArrayList<Integer> all = new ArrayList<Integer>();
//        for (int i = 1 ;; i++) {
//            if (all.size() + i > 100000) break;
//            for (int j = 0; j < i; j++)
//                all.add(i);
//        }
//        PrintWriter out = new PrintWriter("my.out");
////       PrintWriter out = new PrintWriter(System.out);
//        out.println(all.size() + " " + 100000);
//        for (int i = 0; i < all.size(); i++)
//            out.print(all.get(i) + " ");
//        Random random = new Random();
//        for (int i = 0; i < 100000; i++) {
//            int l = 1 + random.nextInt(all.size());
//            int r = 1 + random.nextInt(all.size());
//            if (l > r) {
//                int t = l;
//                l = r;
//                r = t;
//            }
//            out.println(l + " " + r);
//        }
//        out.flush();
//    }
//}

import java.util.*;
import java.io.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
//        InputStream inputStream = new FileInputStream("my.in");
        OutputStream outputStream = System.out;
//        OutputStream outputStream = new FileOutputStream("my.out");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskD {
    int n;
    int m;
    int[] a;
    Map<Integer, Integer> count = new TreeMap<Integer, Integer>();
    List<Integer> useful = new ArrayList<Integer>();
    short[][] cnt;
    int[][] cnt2;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long time0 = System.currentTimeMillis();
        n = in.nextInt();
        m = in.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            Integer was = count.get(a[i]);
            if (was == null)
                was = 0;
            count.put(a[i], was + 1);
        }
        for (Map.Entry<Integer, Integer> entry : count.entrySet())
            if (entry.getValue() >= entry.getKey())
                useful.add(entry.getKey());
        cnt = new short[useful.size()][n + 1];
        cnt2 = new int[useful.size()][];
        for (int i = 0; i < cnt.length; i++) {
            int number = useful.get(i);
            if (count.get(number) > Short.MAX_VALUE) {
                cnt2[i] = new int[n + 1];
                cnt[i][0] = -1;
                for (int j = 1; j <= n; j++) {
                    cnt2[i][j] = cnt2[i][j - 1];
                    if (a[j - 1] == number)
                        cnt2[i][j]++;
                }
            } else {
                for (int j = 1; j <= n; j++) {
                    cnt[i][j] = cnt[i][j - 1];
                    if (a[j - 1] == number)
                        cnt[i][j]++;
                }
            }
        }
        long time1 = System.currentTimeMillis();
//        if (time1 - time0 >= 2000)
//            throw new RuntimeException();
        int[] ret = new int[m];
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
        }
        for (int j = 0; j < cnt.length; j++) {
            if (cnt[j][0] == -1) {
                for (int i = 0; i < m; i++) {
                    if (cnt2[j][r[i]] - cnt2[j][l[i] - 1] == useful.get(j))
                        ret[i]++;
                }
            } else {
                for (int i = 0; i < m; i++) {
                    if (cnt[j][r[i]] - cnt[j][l[i] - 1] == useful.get(j))
                        ret[i]++;
                }
            }
        }
        for (int i = 0; i < m; i++)
            out.println(ret[i]);
        System.err.println("Time = " + (System.currentTimeMillis() - time0));
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

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

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