N,Q = gets.split.map &:to_i
C = gets.split.map &:to_i

n2=1
while(n2<N)
    n2 *= 2
end

$SegTree = Array.new(2*n2-1){[]}
C.each_with_index do |c,i|
    $SegTree[i+n2-1][0] = c
end 

(n2-2).downto(0) do |i|
    $SegTree[i] = ($SegTree[i*2+1] + $SegTree[i*2+2]).uniq
end

def query(a,b,k,l,r)
    return [] if (b<=l || r<=a)
    return $SegTree[k] if (a<=l && r<=b)

    lv = query(a,b,k*2+1,l, (l+r)/2)
    rv = query(a,b,k*2+2,(l+r)/2,r)
    (lv + rv).uniq
end


Q.times do
    l,r = gets.split.map &:to_i
    p query(l-1,r,0,0,n2).count
end