const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const solve = (input) => {
  const [head, s, ...cmds] = input.split("\n")
  const [n, q] = head.split(" ")
  const grm = s.split("")
  const isDead = (s, move) => {
    const moved = s + move
    return moved < 0 || n - 1 < moved
  }
  // cmdMap
  let moves = {}
  let timeMap = {}
  let dead = 0
  let cmdd = cmds
    .map((c) => c.split(" "))
    .map(([t, lr], time) => {
      let current = moves[t] || []

      const moveToR = lr === "L" ? -1 : 1
      moves[t] = [...current, moveToR]
      return [t, moveToR]
    })
  let gmap = {}
  grm.map((c, i) => {
    gmap[c] = [...(gmap[c] || []), i]
  })
  // console.log(cmdd, gmap, moves)
  grm.map((initial, initI) => {
    let currS = initial
    let currI = initI
    // console.log("========")
    for (let i = 0; i < cmdd.length; i++) {
      const [target, move] = cmdd[i]
      // console.log(currS, currI, "->", move, target)
      if (moves[currS] === undefined) {
        return
      }
      if (currS !== target) {
        continue
      }
      if (isDead(currI, move)) {
        dead++
        return
      } else {
        currI = currI + move
        currS = grm[currI]
      }
    }
  })

  return n - dead
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}
