var
 f,g:text;
 a,t,pred:array[1..100000]of longint;
 niz:array[1..100000,1..60]of longint;
 br:array[1..60]of longint;
 i,j,n,k,res,q,w,max:longint;
Function moze (vr,poc,kraj:longint):boolean;
 var
  l,d,s:longint;
  nadjen:boolean;
 begin
 nadjen:=false;
  l:=1;
  d:=br[vr];
  while (d-l >1)and(not nadjen) do begin
   s:=(l+d)div 2;
   if (niz[vr][s]>=poc)and(niz[vr][s]<=kraj) then  nadjen:=true
   else if niz[vr][s]>kraj then d:=s
                           else l:=s;

  end;
   if (niz[vr][l]>=poc)and(niz[vr][l]<=kraj) then  nadjen:=true;
   if (niz[vr][d]>=poc)and(niz[vr][d]<=kraj) then  nadjen:=true;
   if nadjen then moze:=true
   else moze:=false;
 end;
begin
 assign(f,'knjige.in');
 reset(f);
 assign(g,'knjige.out');
 rewrite(g);
 readln(f,n,k);
 max:=0;
 for i:=1 to n do begin
  read(f,a[i]);
  if a[i]>max then max:=a[i];
 end;
 if n<=1 then begin
  for i:=1 to max do t[i]:=0;
   for i:=1 to n do begin
      pred[i]:=t[a[i]];
      t[a[i]]:=i;
  end;
  for i:=1 to k do begin
    res:=0;
    readln(f,q,w);
    for j:=q to w do if pred[j]<q then res:=res+1;
    writeln(g,res);
  end;
 end
else if max<=60 then begin
 for i:=1 to n do
  for j:=1 to max do niz[i][j]:=0;
  for i:=1 to max do br[i]:=0;
 for i:=1 to n do begin
  br[a[i]]:=br[a[i]]+1;
  niz[a[i]][br[a[i]]]:=i;
 end;
 for i:=1 to k do begin
  res:=0;
  readln(f,q,w);
  for j:=1 to max do if(br[j]>0)and moze(j,q,w) then res:=res+1;
  writeln(g,res);
 end;
end;
close(f);
close(g);
end.

