import Control.Monad
import Data.Array

data Dir = L | R deriving (Eq, Read)

-- ### IO ###

main = do
    [pos_len,spl_len] <- (map read . words) <$> getLine :: IO [Int]
    field <- listArray (1,pos_len) <$> getLine
    spells <- replicateM spl_len readSpell
    let left = binSearch field (1,pos_len) (findLeftmostNonZero spells pos_len) R
    let right = binSearch field (1,pos_len) (findRightmostNonLim spells pos_len) L
    print $ right - (left - 1)

readSpell :: IO (Char, Dir)
readSpell = do
    [t:_,d] <- words <$> getLine :: IO [String]
    return (t, read d)

-- ## Algos ###

{- 
-- Binary search over {arr}, ranging from {l} to {r},
-- with the searching strategy {f}, where the direction
-- {pref} is preferred when the border lands between two elements.
-}
binSearch :: Array Int a -> (Int, Int) -> (Array Int a -> Int -> Dir) -> Dir -> Int
binSearch arr (l,r) f pref
    | l   == r  = r
    | l+1 == r  = case (f arr l, f arr r) of
        (R,R) -> r
        (R,L) -> case pref of L->l; R->r
        (L,L) -> l
        (L,R) -> error "Non-consistent searching strategy"
    | otherwise = let curPos = (l+r) `div` 2 in
        case f arr curPos of
            L -> binSearch arr (l, curPos) f pref
            R -> binSearch arr (curPos, r) f pref

---- # searching strategies

findLeftmostNonZero :: [(Char,Dir)] -> Int -> Array Int Char -> Int -> Dir
findLeftmostNonZero spells lim field curPos =
        if performSpell spells field lim curPos == 0
            then R else L

findRightmostNonLim :: [(Char,Dir)] -> Int -> Array Int Char -> Int -> Dir
findRightmostNonLim spells lim field curPos =
        if performSpell spells field lim curPos == lim+1
            then L else R

---- # wizardry

performSpell :: [(Char,Dir)] -> Array Int Char -> Int -> Int -> Int
performSpell spells field lim iniPos =
    foldl (spellStep field lim) iniPos spells    

spellStep :: Array Int Char -> Int -> Int -> (Char,Dir) -> Int
spellStep field lim cur_pos (target,dir)
    | cur_pos<1 || lim<cur_pos = cur_pos
    | field!cur_pos == target = case dir of
            L -> cur_pos - 1
            R -> cur_pos + 1
    | otherwise  = cur_pos
