fun main(args:Array<String>) {
    var n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map {it.toInt()}
 
    var res = 0
 
    for(i in 0..(n-1)) {
        if (a[a[i]-1]-1 == i) {
            res++
        }
    }
 
    println(res/2)
}