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

puts counts