n,q = gets.strip.split.map(&:to_i)
c = gets.strip.split.map(&:to_i)
a = []
n.times do |i|
  if i == 0
    a[0] = Hash.new(0)
    a[0][c[0]] += 1
  else
    a[i] = a[i-1].dup
    a[i][c[i]] += 1
  end
end
q.times do
  l,r = gets.strip.split.map(&:to_i)
  ans = 0
  a[r-1].each do |k,v|
    ans += 1 if l == 1 || v - a[l-2][k] > 0
  end
  p ans
end
