nq = STDIN.gets().split(" ")
c = STDIN.gets().split(" ")

def count(c, l, r)
  tmp = []
  for i in l-1..r-1
    tmp[c[i].to_i] = true
  end
  res = 0
  tmp.each do |t|
    if t
      res +=1
    end
  end
  return res
end

out = []
for i in 1..nq[1].to_i
  lr = STDIN.gets().split(" ")
  res = count(c, lr[0].to_i, lr[1].to_i)
  out.push(res)
end

out.each do |o|
  puts o
end