module Fenwick = struct
    module type Element =
        sig
            type t
            val proc: t -> t -> t
            val zero: t
        end
    module Make(E: Element) = struct
        let create n = Array.make (n + 1) E.zero

        let update bit index value =
            let n = Array.length bit - 1 in
            let rec loop ii =
                if ii <= n then (
                    bit.(ii) <- E.proc bit.(ii) value;
                    loop (ii + (ii land (-ii)))
                )
            in
            loop index

        let query bit index = 
            let rec loop ii acc =
                if ii > 0 then (
                    loop (ii - (ii land -ii)) (E.proc bit.(ii) acc)
                ) else acc
            in
            loop index E.zero
    end
end;;
type q = { r:int; l:int; idx:int };;
Scanf.scanf "%d %d" (fun n q ->
    let solve arr n query q =
        let ans = Array.make q 0 in
        let module F = Fenwick.Make (struct type t = int let proc = (+) let zero = 0 end) in
        let bit = F.create n in
        let last_visit = Array.make 500001 (-1) in

        let rec loop i qi =
            if i < n then (
                if last_visit.(arr.(i)) <> -1 then
                    F.update bit (last_visit.(arr.(i)) + 1) (-1);
                last_visit.(arr.(i)) <- i;

                F.update bit (i + 1) 1;

                let rec loop2 qi =
                    if qi < q && query.(qi).r = i then  (
                        ans.(query.(qi).idx) <-
                            F.query bit (query.(qi).r + 1) - F.query bit (query.(qi).l);
                        loop2 (qi + 1)
                    ) else qi
                in
                loop (i + 1) (loop2 qi)
            )
        in
        loop 0 0;
        Array.iter (Printf.printf "%d\n") ans
    in
    let c = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let query = Array.init q (fun i -> Scanf.scanf " %d %d" (fun l r -> { r = r - 1; l = l - 1; idx = i})) in
    Array.sort compare query;
    solve c n query q
)