require "numo/narray"

class BIT
  def initialize(size)
    @n, @a = size, Numo::Int64.zeros(size + 1)
  end

  def query(i)
    s = 0
    while i > 0
      s = s + @a[i]
      i -= i & -i
    end
    s
  end

  def update(i, x)
    while i <= @n
      @a[i] = @a[i] + x
      i += i & -i
    end
  end
end

n, q = gets.split.map &:to_i
prevs = [-1] * n
ranges = []

gets.split.each_with_index do |c, i|
  c = c.to_i - 1
  if prevs[c] >= 0
    ranges << [q, prevs[c], i]
  end
  prevs[c] = i
end

q.times do |i|
  l, r = gets.split.map &:to_i
  ranges << [i, l-1, r-1]
end

ranges = ranges.sort_by { |(i, x, y)| -x * q - i }
tree = BIT.new(n)

results = []

ranges.each do |(i, x, y)|
  if i == q
    tree.update(y, 1)
  else
    results[i] = y - x + 1 - tree.query(y)
  end
end

puts results
