(read-line)

(def rabbit-list
  (vec (for [e (clojure.string/split (read-line) #"\s")]
    (Integer/parseInt e))))

(defn friend? [n coll]
  (= n (nth coll (dec (nth coll (dec n))))))

(println (int (apply +
  (for [r rabbit-list]
    (if (friend? r rabbit-list) 1/2 0)))))