import qualified Data.Map as Map

main = do
    [n,q] <- (map read . words) <$> getLine :: IO [Int]
    s <- getLine
    let iniLs = replicate n 1
    let iniMp = buildMap s 1 Map.empty
    finishedLs <- spell iniMp iniLs n q
    print $ sum finishedLs

buildMap :: String -> Int -> Map.Map Char [Int] -> Map.Map Char [Int]
buildMap [] _ mp = mp
buildMap (x:xs) n mp = insertMap x n (buildMap xs (n+1) mp)

insertMap :: Char -> Int -> Map.Map Char [Int] -> Map.Map Char [Int]
insertMap c n mp =
    case Map.lookup c mp of
        Just ls -> Map.insert c (n:ls) mp
        _       -> Map.insert c [n] mp

spell :: Map.Map Char [Int] -> [Int] -> Int -> Int -> IO [Int]
spell mp ls _ 0 = return ls
spell mp ls n q = do
    [t:_,d:_] <- words <$> getLine :: IO [String]
    case Map.lookup t mp of
        Just letterLs -> do
            let diff = subLs letterLs ls
            let subls = zipWith subtract diff ls
            let ls' = case d of
                    'L' -> zipWith (+) subls (tail diff ++ [0])
                    'R' -> zipWith (+) subls (0:diff)
            spell mp ls' n (q-1)
        Nothing -> spell mp ls n (q-1)

-- Assuming 1st arg is ordered
subLs :: [Int] -> [Int] -> [Int]
subLs = zoLsAux 1
    where
        zoLsAux _ [] ns = replicate (length ns) 0
        zoLsAux _ _ [] = []
        zoLsAux ac letterLs@(x:xs) (n:ns)
            | x==ac     = n:(zoLsAux (ac+1) xs ns)
            | otherwise = 0:(zoLsAux (ac+1) letterLs ns)

 
