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 = rec2(0, targets)
    def rec2(count: Int, map: Map[Int, Int]): Int = {
        if (map.isEmpty || map.size==1) count
        else {
            val rabbit1 = map.head
            val rabbit1_key = rabbit1._1
            val rabbit1_like = rabbit1._2
            val rabbit1_like_like = map(rabbit1_like)

            if (rabbit1_key == rabbit1_like_like) rec2(count+1, map-rabbit1_key-rabbit1_like)
            else rec2(count, map-rabbit1_key-rabbit1_like)

        }
    }
    
    println(result)
}