(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=[(0...n).map{0}]
cs.each{|c|
    tmp << tmp[-1].dup
    tmp[-1][c]+=1
}

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