func main () {
    let nq = readLine()!.split(separator: " ").map{String($0)}
    let cList = readLine()!.split(separator: " ").map{Int($0)!}
    var lrList = [[Int]]()
    while let lr = readLine() {
        lrList.append(lr.split(separator: " ").map{Int($0)!})
    }
    for lr in lrList {
        var set: Set<Int> = []
        for index in lr[0]-1...lr[1]-1 {
            set.insert(cList[index])
        }
        print(set.count)
    }
}

main()

