program knjige;
var n,k,i,x,y:longint;
    f,g:text;
    a,dp:array[0..100005] of longint;
    ok:array[0..100005] of boolean;
begin
  assign(f,'knjige.in');
  reset(f);
  assign(g,'knjige.out');
  rewrite(g);
  readln(f,n,k);
  dp[0]:=0;
  for i:=1 to n do begin
  read(f,a[i]);
  if not(ok[a[i]]) then dp[i]:=dp[i-1]+1
  else dp[i]:=dp[i-1];
  ok[a[i]]:=true;
  end;
  for i:=1 to k do begin
  readln(f,x,y);
  writeln(g,dp[y]-dp[x]+1);
  end;
  close(f);
  close(g);
end.
