{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.MArray as MA
import Control.Monad.ST



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

newtype MyGraph = MyGraph (A.Array Int [Int])

listToGraph :: Int -> [(Int, Int)] -> MyGraph
listToGraph n paths = MyGraph $ STA.runSTArray $ do
    a <- MA.newArray (1, n) []
    forM_ paths $ \(from, to) -> do
        f <- MA.readArray a from
        MA.writeArray a from $ to : f
        t <- MA.readArray a to
        MA.writeArray a to $ from : t
    pure a

getPaths :: Int -> MyGraph -> [Int]
getPaths i (MyGraph lst) = lst A.! i

solve :: Int -> [Int] -> [(Int, Int)] -> Int
solve n heights paths = let 
    hs :: UA.UArray Int Int 
    hs = A.listArray (1, n) heights
    grp = listToGraph n paths
    isGood i = case getPaths i grp of
        [] -> True
        paths -> let
            mine = hs A.! i
            in
            all ((mine>) . (hs A.!)) paths
    in 
    length $ filter isGood [1..n]


main :: IO ()
main = do
    (n, m) <- readTuple2
    heights <- readInts
    paths <- replicateM m readTuple2
    print $ solve n heights paths



