GC.disable

class BinaryIndexTree
  attr_reader :bit, :size

  def initialize(size, init: 0)
    @bit = Array.new(size, init)
    @size = size
  end

  def sum(i)
    s = 0

    while i > 0
      s += bit[i]
      i -= i & -i
    end

    s
  end

  def add(i, x)
    while i < size
      bit[i] += x
      i += i & -i
    end
  end
end

N, Q = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)
queries = Q.times.map.with_index { |i|
  l, r = gets.split.map(&:to_i)

  [i, l, r]
}

ans = Array.new(Q, -1)
last = Array.new(N + 1)
idx = 0
bit = BinaryIndexTree.new(N + 1)

queries.sort_by { |i, l, r| r }.each do |i, l, r|
  while idx < r
    c = C[idx]

    if last[c]
      bit.add(last[c], 1)
    end

    last[c] = idx + 1
    idx += 1
  end

  ans[i] = (r - l + 1) - (bit.sum(r) - bit.sum(l - 1))
end

puts ans
