object Main extends App {
    val n = io.StdIn.readInt
    val as = io.StdIn.readLine.split(" ").map(_.toInt)

    val targets = rec1(1, Map.empty)
    def rec1(index: Int, map: Map[Int, Int]): Map[Int, Int] = {
        if (n < index) map
        else {
            rec1(index+1, map+(index -> as(index-1)))
        }
    }

    val result = targets.count { case (k,v) => targets(v) == k }
    println(result/2)
}