class SegTree
	def initialize(n, ident, &op)
		@ident, @op = ident, op
		size = 1
		size *= 2 until size >= n
		@n, @size = n, size
		@ary = [ident] * (size * 2 - 1)
	end
      
      def [](i); @ary[i + @size]; end

	def []=(i, x)
		i += @size - 1
		loop do
			@ary[i] = x
			break if i <= 0
			i = (i - 1) / 2
			x = @op[@ary[i*2+1], @ary[i*2+2]]
		end
	end

	def fold(l = 0, r = @size, i = 0, k = 0, q = @size)
		return @ary[i] if r - l == 1
		if l <= k and r <= q
			@ary[i]
		else
			c = (k + q) / 2
			sum = @ident
			sum = @op[sum, fold(l, r, i*2+1, k, c)] if l < c and k < r
			sum = @op[sum, fold(l, r, i*2+2, c, q)] if l < q and c < r
			sum
		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 }
tree = SegTree.new(n, 0) { |x, y| x + y }

results = []

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

puts results