object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, q = sc.nextInt()
  val c = Array.fill(n)(sc.nextInt())
  val lr = Array.fill(q)(sc.nextInt, sc.nextInt)
  lr.map(color).foreach(println)

  def color(v:(Int, Int)): Int = {
    c.slice(v._1 - 1, v._2).distinct.length
  }
}