import Data.List
import Data.Tuple

main :: IO ()
main =
  fmap read getLine >>=
  \n -> fmap ((zipWith (,) [1..n]) . (map read) . words) getLine >>=
  \as -> putStrLn $ show $ sub as

sub :: [(Int,Int)] -> Int
sub [] = 0
sub (a:as)
  | swap a `elem` as = 1 + (sub as)
  | otherwise = sub as

remove' :: Eq a => a -> [a] -> [a]
remove' _ [] = []
remove' n (x:xs)
  | n == x    = xs
  | otherwise = x : (remove' n xs)