{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> B.ByteString -> VU.Vector (Char, Char) -> Int
solve !n !q !s !tds =
  binsearchR 0 (B.length s) - binsearchL (-1) (B.length s - 1) + 1
 where
  remainLeft !n = simulate n >= 0
  remainRight !n = simulate n < B.length s

  simulate !n = VU.foldr'
    (\(!t, !d) !i -> if i < 0 || i >= B.length s
      then i
      else
        let ch = B.index s i
        in  if t == ch then (if d == 'L' then i - 1 else i + 1) else i
    )
    n
    (VU.reverse tds)

  -- search in (x,y]
  binsearchL !x !y
    | y - x == 1
    = y
    | otherwise
    = let !z = (x + y) `div` 2
      in  if remainLeft z then binsearchL x z else binsearchL z y

  -- search in [x,y)
  binsearchR !x !y
    | y - x == 1
    = x
    | otherwise
    = let !z = (x + y) `div` 2
      in  if remainRight z then binsearchR z y else binsearchR x z

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
