program Knjige;

type    Tniz=record
        bod, bdo:longint;
        end;

        Tkontrol=record
        n,k:longint;
        end;

        neez=array[1..10000] of longint;

var k, n:longint;
tmp:tkontrol;
data:array[1..100000] of longint;
ns:array[1..100000] of Tniz;
loop:longint;

{procedure GetKontrol(s:string);
var
i, state:longint;
kod:integer;
kstr, nstr:string;
begin
for i:=1 to length(s) do
        if s[i]=' ' then state:=2 else
        case state of
        1:kstr:=kstr+s[i];
        2:nstr:=nstr+s[i];
        end;
val(kstr, k, kod);
val(nstr, n, kod);
end;}

procedure GetAut(s:string);
var
i, num, kod:longint;
state:integer;
wrt:string;
tmp:array[1..10000] of longint;
begin
wrt:='';
state:=1;
for i:=1 to length(s) do if s[i]=' ' then
        begin
        val(wrt, num, kod);
        tmp[state]:=0;
        data[state]:=num;
        wrt:='';

        state:=state+1;
        end else
        wrt:=wrt+s[i];
end;

{function GetNiz(s:string):Tniz;
var i, state:longint;
astr, bstr:string;
a, b:int64;
tmp:tniz;
begin
state:=1;
for i:=1 to length(s) do if s[i]=' ' then state:=2 else
        case state of
        1:astr:=astr+s[i];
        2:bstr:=bstr+s[i];
        end;
val(astr, a, state);
val(bstr, b, state);
tmp.bod:=a;
tmp.bdo:=b;
GetNiz:=tmp;



end;}

procedure Unos;
var i:longint;
tmp1, tmp2:longint;
rd:string;
f:text;
begin
assign(f, 'knjige.in');
reset(f);
readln(f, n, k);
//GetKontrol(rd);
readln(f, rd);
GetAut(rd);
for i:=1 to k do
        begin
        readln(f, tmp1, tmp2);
        ns[i].bod:=tmp1;
        ns[i].bdo:=tmp2
        //ns[i]:=getniz(rd);
        end;
close(f);
end;

function Count(num:longint):longint;
var i, j:longint;
tmp:longint;
auts:array[1..10000] of longint;
naut:longint;
found:boolean;
begin
found:=false;
naut:=1;
for i:=ns[num].bod to ns[num].bdo do
        begin
        found:=false;
        for j:=1 to n do
                if data[i]=auts[j] then
                        begin
                        found:=true;
                        break;
                        end;
        if not found then
                begin
                auts[naut]:=data[i];
                naut:=naut+1;
                end;
        end;
count:=naut-1;

end;

procedure Izlaz;
var f:text;
i:longint;
begin

assign(f, 'knjige.out');
rewrite(f);
for i:=1 to k do writeln(f, count(i));
close(f);

end;

begin
Unos;
Izlaz;


end.
