"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}


function main() {
  var n = next();
  var q = next();
  var c = nexts(n);
  var lr = nextm(q,2)
  for (var i=0;i<n;i++){
    var t = --c[i];
    cc[t].push(i+1);
  }
  let inf  = n*2;
  let ans = xArray(0,q);
  let last = xArray(inf,n);
  let next = xArray(Array(1), n);
  for (let i=0;i<N;i++) {
    let v = last[c[i]];
    if (v != N) {
      next[v].push(i);
    }
    last[c[i]] = N;
  }
  let qs = xArray(Array(n),n);
  for (let qi=0;qi<q;qi++) {
    let (l, r) = lr[qi];
    qs[l].push((r, qi));
  }
  //println!("p{:?}", next);
  var bit = new BIT(n+1);
  for (let x = N-1; x>=0;x--) {
    if( next[x].length >0){
      bit.add(next[x][0],1);
    }
    for (let ri of qs[x]) {
      let (r,i) = ri
      //println!("sum={}", bit.sum(r));
      ans[qi] = (r - x + 1) - bit.sum(r);
    }
  }

  for (let a of ans) {
    console.log( a);
  }
}

class BIT{
  constructor(n){
  this.d = Array(n+1).fill(0);
  }
  add( i, x){
    while (i < this.d.length){
      this.d[i] +=x;
      i += i & -i;
    }
  }
  sum(i){
    let ret = 0;
    while (i>0){
      ret += this.d[i];
      i -= i& -i;
    }
    return ret;
  }
}
