open Hashtbl
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun i -> Scanf.scanf " %d" @@ fun a -> min i @@ a - 1, max i @@ a - 1
let h = create n
let _ = Array.iteri (fun i a -> replace h a @@ try find h a + 1 with _ -> 1) a_s; fold (fun _ c s -> s + if c = 2 then 1 else 0) h 0 |> Printf.printf "%d\n"