program knjige;
var t,x,y,n,k,br,i,j:longint; m,a,b:array[1..1000] of integer;
 c:array[1..1000,1..1000] of longint; f,g:text;



begin
assign(f,'knjige.in');
assign(g,'knjige.out');
reset(f);
rewrite(g);
readln(f,n,k);
br:=0;
i:=1;
          for j:=1 to n do
            begin
             read(f,a[j]);
             b[a[j]]:=b[a[j]]+1;
             m[a[j]]:=m[a[j]]+1;
             if b[a[j]]=1 then br:=br+1;
             c[i,j]:=br;
            end;

br:=0;
b[a[1]]:=b[a[1]]-1;
for i:=2 to n do
 begin
   br:=0;
   for j:=i to n do
    begin
     if b[a[j]]>0 then
                         begin
                          br:=br+1;
                          b[a[j]]:=0;
                       end;
     c[i,j]:=br;

    end;
    m[a[i]]:=m[a[i]]-1;
   for t:=1 to 60 do b[t]:=m[t];

 end;
for i:=1 to k do
 begin
  readln(f,x,y);
  writeln(g,c[x,y]);
 end;
close(f);
close(g);
 end.

