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.util.HashSet;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        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 m = in.scanInt();
            int arr[] = new int[n + 1];
            HashMap<Integer, Integer> hm = new HashMap();
            for (int i = 1; i <= n; i++) {
                arr[i] = in.scanInt();
                if (hm.containsKey(arr[i])) {
                    hm.put(arr[i], hm.get(arr[i]) + 1);
                } else {
                    hm.put(arr[i], 1);
                }
            }


            HashMap<Integer, Integer> mapp = new HashMap<>();
            int index = 0;
            HashSet<Integer> kamna = new HashSet<>();
            for (Map.Entry<Integer, Integer> hhh : hm.entrySet())
                if (hhh.getValue() >= hhh.getKey()) kamna.add(hhh.getKey());
            for (int k : kamna) mapp.put(k, index++);


            int prefix[][] = new int[n + 1][index + 1];
            for (int i = 1; i <= n; i++) {
                if (kamna.contains(arr[i])) {
                    int iii = mapp.get(arr[i]);
                    prefix[i][iii]++;
                }
                for (int j = 0; j < kamna.size(); j++) prefix[i][j] += prefix[i - 1][j];
            }


            while (m-- > 0) {
                int l = in.scanInt();
                int r = in.scanInt();
                int c = 0;
                for (int k : kamna) {
                    int ii = mapp.get(k);
                    if (prefix[r][ii] - prefix[l - 1][ii] == k) c++;
                }
                out.println(c);
            }
        }

    }

    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 I = 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') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

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

    }
}

