import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  getLine
  solve <$> getl (wrds toInt) >>= print

solve :: [Int] -> Int
solve xs = f 0 $ zip [1..] xs
  where
    f c [] = c
    f c ((i,j):rs) = if (j,i) `elem` rs then f (c + 1) rs
                     else f c rs

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine
