N, Q = gets.chomp.split(' ').map(&:to_i)
cs = gets.chomp.split(' ').map(&:to_i)
lrs = []
Q.times do
  lrs << gets.chomp.split(' ')
end
lrs.each do |lr|
  a, b = lr.map(&:to_i)
  d = cs.shift(a-1)
  puts cs.take((b-a+1)).uniq.count
  cs = cs.unshift(d).flatten
end