output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N Q
      s
      t_1 d_1
      \vdots
      t_{Q} d_Q
attempt: import sys
  
  sys.setrecursionlimit(1000000)
  # def input():
  #    return sys.stdin.readline()[:-1]
  
  """
  n=int(input())
  for i in range(n):
      a[i]=int(input())
      a[i],b[i]=map(int,input().split())
  a=[int(x) for x in input().split()]
  n,m=map(int,input.split())
  from operator import itemgetter
  a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
  print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
  print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
  print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
  print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
  print(sorted(a, reverse=True))  # 降順にソート
  a.sort()  # 破壊的にソート、sorted() よりも高速
  try: # エラーキャッチ list index out of range
      for i in range():
          k=b[i]
  except IndexError as e:
      print(i)
  """
  
  test_data1 = """\
  3 4
  ABC
  A L
  B L
  B R
  A R
  """
  
  test_data2 = """\
  2 3 0
  4 5 6
  7 8 9
  -1 2 -5
  """
  
  test_data3 = """\
  10 15
  SNCZWRCEWB
  B R
  R R
  E R
  W R
  Z L
  S R
  Q L
  W L
  B R
  C L
  A L
  N L
  E R
  Z L
  S L
  """
  td_num = 1
  
  
  def GetTestData(index):
      if index == 1:
          return test_data1
      if index == 2:
          return test_data2
      if index == 3:
          return test_data3
  
  
  if False:
      with open("../test.txt", mode="w") as f:
          f.write(GetTestData(td_num))
      with open("../test.txt") as f:
          # Start Input code ---------------------------------------
          n, q = map(int, f.readline().split())
          s = str(f.readline())
          t = [""] * q
          d = [""] * q
          for i in range(q):
              t[i], d[i] = map(str, f.readline().split())
          # End Input code ---------------------------------------
  else:
      for i in range(1):
          # Start Input code ---------------------------------------
          n, q = map(int, input().split())
          s = str(input())
          t = [""] * q
          d = [""] * q
          for i in range(q):
              t[i], d[i] = map(str, input().split())
          # End Input code ---------------------------------------
  
  
  def order(x):  # return goal of x-th golem
      l = x
      for i in range(q):
          if s[l] == t[i]:
              l += 1 if d[i] == "R" else -1
              if l >= n or l < 0:
                  rt = 1 if l >= n else -1
                  return rt
      return 0
  
  
  ans = 0
  
  # find leftest golem
  lc = 0
  rc = n - 1
  lv = order(lc)
  rv = order(rc)
  while rc - lc > 1:
      cc = int((rc + lc) / 2)
      cv = order(cc)
      if cv == 1:
          rc = cc
          rv = cv
          cc = int((lc + cc) / 2)
      else:
          lc = cc
          lv = cv
          cc = int((cc + rc) / 2)
  r = lc if rv == 1 else rc
  
  # find rightest golem
  lc = 0
  rc = n - 1
  lv = order(lc)
  rv = order(rc)
  while rc - lc > 1:
      cc = int((rc + lc) / 2)
      cv = order(cc)
      if cv == -1:
          lc = cc
          lv = cv
          cc = int((cc + rc) / 2)
      else:
          rc = cc
          rv = cv
          cc = int((lc + cc) / 2)
  l = rc if lv == -1 else lc
  
  print(r - l + 1)
  
problem_description: Statement
  
  There are N squares numbered 1 to N from left to right. Each square has a
  character written on it, and Square i has a letter s_i. Besides, there is
  initially one golem on each square.
  
  Snuke cast Q spells to move the golems.
  
  The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or
  `R`. When Snuke cast this spell, for each square with the character t_i, all
  golems on that square moved to the square adjacent to the left if d_i is `L`,
  and moved to the square adjacent to the right if d_i is `R`.
  
  However, when a golem tried to move left from Square 1 or move right from
  Square N, it disappeared.
  
  Find the number of golems remaining after Snuke cast the Q spells.
samples: [{"input": "3 4\n    ABC\n    A L\n    B L\n    B R\n    A R", "output": "2\n    \n\n  * Initially, there is one golem on each square.\n  * In the first spell, the golem on Square 1 tries to move left and disappears.\n  * In the second spell, the golem on Square 2 moves left.\n  * In the third spell, no golem moves.\n  * In the fourth spell, the golem on Square 1 moves right.\n  * After the four spells are cast, there is one golem on Square 2 and one golem on Square 3, for a total of two golems remaining.\n\n* * *"}, {"input": "8 3\n    AABCBDBA\n    A L\n    B R\n    A R", "output": "5\n    \n\n  * After the three spells are cast, there is one golem on Square 2, two golems on Square 4 and two golems on Square 6, for a total of five golems remaining.\n  * Note that a single spell may move multiple golems.\n\n* * *"}, {"input": "10 15\n    SNCZWRCEWB\n    B R\n    R R\n    E R\n    W R\n    Z L\n    S R\n    Q L\n    W L\n    B R\n    C L\n    A L\n    N L\n    E R\n    Z L\n    S L", "output": "3"}]