(n,q)=gets.split.map(&:to_i)
cs=gets.split.map{|x| x.to_i-1}
qs=ARGF.map{|s|s.split.map{|x| x.to_i}}

tmp=[{}]
cs.each{|c|
    tmp << tmp[-1].dup
    tmp[-1][c]||=0
    tmp[-1][c]+=1
}

qs.each{|l,r|
    
    res = tmp[r].count{|c,v| v - (tmp[l-1][c]||0) > 0 }
    print res,"\n"
    }