fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map { it.toInt() - 1 }

    var array = Array(n) { mutableSetOf<Int>() }
    for ((i, a) in an.withIndex()) {
        array[a].add(i)
    }

    var c = 0
    for ((i, a) in an.withIndex()) {
        if(array[i].contains(a)){
            c++
        }
    }
    println(c/2)
}