{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.ByteString.Char8 as B

solve :: Int -> Int -> B.ByteString -> VU.Vector (Char, Char) -> Int
solve !n !q !s !tds = (\(l, r) -> r - l - 1) $ simulate
 where
  goRight t k = if k < n - 1 && t == B.index s (k + 1) then k + 1 else k
  goLeft t k = if k > 0 && t == B.index s (k - 1) then k - 1 else k

  simulate = VU.foldr'
    (\(!t, !d) (!l, !r) ->
      if d == 'L' then (goRight t l, r) else (l, goLeft t r)
    )
    (-1, n)
    tds

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n, q) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  s   <- B.getLine
  tds <-
    VU.replicateM q
    $   ((\[x, y] -> (B.head x, B.head y)) . B.words)
    <$> B.getLine
  print $ solve n q s tds
