-module('Main').
-export([main/1]).

main(_) -> 
    {ok, [N, Q]} = io:fread("", "~d ~d"),
    Seq = [XX || XX <- lists:map(fun(_) ->
                                         {ok, [X]} = io:fread("", "~d"),
                                         X
                                 end,
                                 lists:seq(1, N))],
    [XX || XX <- lists:map(fun(_) ->
                                   {ok, [L, R]} = io:fread("", "~d ~d"),
                                   answer(L, R, Seq)
                           end,
                           lists:seq(1, Q))],
    halt().

answer(L, R, Seq) ->
    Sub = lists:sublist(Seq, L, R - L + 1),
    Set = sets:from_list(Sub),
    io:format("~p~n", [sets:size(Set)]).