import Data.Graph
import qualified Data.Vector.Unboxed as U
import qualified Data.Set as S
import qualified Data.Foldable as F
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as B

solve n m p e = sum $ map count $ cmps where
  count cmp = S.size $ S.intersection (S.fromList cmp) $
    S.fromList [ p U.! (i-1) | i <- cmp ]
  cmps = map F.toList $ components $ buildG (1,n) e

main = do
  [n, m] <- readInts
  p <- U.fromList <$> readInts
  e <- replicateM m $ (\[a,b]->(a,b)) <$> readInts
  print $ solve n m p e

readInts = unfoldr (B.readInt . B.dropWhile (== ' '))
  <$> B.getLine 