import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M

setM :: M.Map Int [Int] -> Int -> Int -> M.Map Int [Int]
setM m k v = if M.member k m
                then M.update (\x -> Just (x++[v])) k m
                else M.insert k [v] m

wayList :: M.Map Int [Int] -> [[Int]] -> M.Map Int [Int]
wayList m [] = m
wayList m (abs:abss) = wayList (setM (setM m a b) b a) abss
        where
            a = abs!!0 :: Int
            b = abs!!1 :: Int

solve m hs [] = []
solve m hs (i:is)
    | ws == Nothing = 1 : solve m hs is
    | all (\x -> hs!!(i-1)>hs!!(x-1)) (fromJust ws) = 1 : solve m hs is
    | otherwise = 0 : solve m hs is
        where
            ws = M.lookup i m

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    hs <- map read . words <$> getLine :: IO [Int]
    abss <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    print $ sum $ solve (wayList M.empty abss) hs [1..n]
