module CharMap = Map.Make (Char)

let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in
  get

let () = Scanf.scanf "%d %d\n%s\n" @@ fun n q s ->
  let tds = Array.init q @@ fun _ -> Scanf.scanf "%c %c\n" @@ fun t d -> t, d in
  let next =
    let next = Array.make (q + 1) CharMap.empty in
    for i = q - 1 downto 0 do
      next.(i) <- CharMap.add (fst tds.(i)) i next.(i + 1)
    done;
    fun i c ->
      try CharMap.find c next.(i)
      with Not_found -> q in
  let dp = memoize (n + q) @@ fun dp (i, j) ->
    0 <= j && j < n && (q <= i || 
    if snd tds.(i) = 'L'
    then 0 <= j - 1 && dp (next (i + 1) s.[j - 1], j - 1)
    else j + 1 < n && dp (next (i + 1) s.[j + 1], j + 1)) in
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init n @@ fun i ->
    if dp (next 0 s.[i], i) then 1 else 0
