fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    var ans = 0
    val list = mutableListOf<Int>()
    list.add(0)
    for (num in readLine()!!.split(" ").map { it.toInt() }) {
        list.add(num)
    }
    for(j in 1..n) {
        if(j == list[list[j]]) {
            ans++
        }
    }
    print(ans / 2)
}