object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN, datQ) = readLine.split(" ").map(_.toInt)
    val datC = readLine.split(" ").map(_.toInt)
    //val query = for(i <- 1 to datN) yield (readLine.split(" ").map(_.toInt))
    for(i <- 1 to datQ){
      val Array(datL, datR) = readLine.split(" ").map(_.toInt)
      var t : Set[Int] = Set();
      for(j <- datL-1 until datR) {
        t = t + datC(j)
      }
      val ans = t.size
      //val ans = datC.slice(datL-1, datR).distinct.length
      println(ans)
    }
  }
}
