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

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

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

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