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: N, Q = map(int, input().split())
  s = input()
  T = [0 for i in range(Q)]
  D = [0 for i in range(Q)]
  for i in range(Q):
      T[i], D[i] = input().split()
  for i in range(Q):
      if T[i] == "A":
          T[i] = 0
      elif T[i] == "B":
          T[i] = 1
      elif T[i] == "C":
          T[i] = 2
      elif T[i] == "D":
          T[i] = 3
      elif T[i] == "E":
          T[i] = 4
      elif T[i] == "F":
          T[i] = 5
      elif T[i] == "G":
          T[i] = 6
      elif T[i] == "H":
          T[i] = 7
      elif T[i] == "I":
          T[i] = 8
      elif T[i] == "J":
          T[i] = 9
      elif T[i] == "K":
          T[i] = 10
      elif T[i] == "L":
          T[i] = 11
      elif T[i] == "M":
          T[i] = 12
      elif T[i] == "N":
          T[i] = 13
      elif T[i] == "O":
          T[i] = 14
      elif T[i] == "P":
          T[i] = 15
      elif T[i] == "Q":
          T[i] = 16
      elif T[i] == "R":
          T[i] = 17
      elif T[i] == "S":
          T[i] = 18
      elif T[i] == "T":
          T[i] = 19
      elif T[i] == "U":
          T[i] = 20
      elif T[i] == "V":
          T[i] = 21
      elif T[i] == "W":
          T[i] = 22
      elif T[i] == "X":
          T[i] = 23
      elif T[i] == "Y":
          T[i] = 24
      elif T[i] == "Z":
          T[i] = 25
  for i in range(Q):
      if D[i] == "L":
          D[i] = 0
      elif D[i] == "R":
          D[i] = 1
  word_of_cell = [0] * N
  for i in range(1, N + 1):
      w = s[i - 1 : i]
      if w == "A":
          word_of_cell[i - 1] = 0
      elif w == "B":
          word_of_cell[i - 1] = 1
      elif w == "C":
          word_of_cell[i - 1] = 2
      elif w == "D":
          word_of_cell[i - 1] = 3
      elif w == "E":
          word_of_cell[i - 1] = 4
      elif w == "F":
          word_of_cell[i - 1] = 5
      elif w == "G":
          word_of_cell[i - 1] = 6
      elif w == "H":
          word_of_cell[i - 1] = 7
      elif w == "I":
          word_of_cell[i - 1] = 8
      elif w == "J":
          word_of_cell[i - 1] = 9
      elif w == "K":
          word_of_cell[i - 1] = 10
      elif w == "L":
          word_of_cell[i - 1] = 11
      elif w == "M":
          word_of_cell[i - 1] = 12
      elif w == "N":
          word_of_cell[i - 1] = 13
      elif w == "O":
          word_of_cell[i - 1] = 14
      elif w == "P":
          word_of_cell[i - 1] = 15
      elif w == "Q":
          word_of_cell[i - 1] = 16
      elif w == "R":
          word_of_cell[i - 1] = 17
      elif w == "S":
          word_of_cell[i - 1] = 18
      elif w == "T":
          word_of_cell[i - 1] = 19
      elif w == "U":
          word_of_cell[i - 1] = 20
      elif w == "V":
          word_of_cell[i - 1] = 21
      elif w == "W":
          word_of_cell[i - 1] = 22
      elif w == "X":
          word_of_cell[i - 1] = 23
      elif w == "Y":
          word_of_cell[i - 1] = 24
      elif w == "Z":
          word_of_cell[i - 1] = 25
  g_leave = [[[0 for i in range(N + 3)] for d in range(2)] for t in range(26)]
  g_enter = [[[0 for i in range(N + 3)] for d in range(2)] for t in range(26)]
  for t in range(26):
      for d in range(2):
          for i in range(1, N + 1):
              if word_of_cell[i - 1] == t and d == 0:
                  g_enter[t][d][0] += 1
                  g_enter[t][d][g_enter[t][d][0]] = i
                  g_leave[t][d][0] += 1
                  g_leave[t][d][g_leave[t][d][0]] = i + 1
              if word_of_cell[i - 1] == t and d == 1:
                  g_enter[t][d][0] += 1
                  g_enter[t][d][g_enter[t][d][0]] = i + 2
                  g_leave[t][d][0] += 1
                  g_leave[t][d][g_leave[t][d][0]] = i + 1
  golem_count = [0] * (N + 2)
  for i in range(1, N + 1):
      golem_count[i] = 1
  print(golem_count)
  import copy
  
  for q in range(Q):
      previous_golem_count = copy.deepcopy(golem_count)
      for i in range(1, g_enter[T[q]][D[q]][0] + 1):
          if D[q] == 0:
              golem_count[g_enter[T[q]][D[q]][i] - 1] += previous_golem_count[
                  g_enter[T[q]][D[q]][i]
              ]
          if D[q] == 1:
              golem_count[g_enter[T[q]][D[q]][i] - 1] += previous_golem_count[
                  g_enter[T[q]][D[q]][i] - 2
              ]
      for i in range(1, g_leave[T[q]][D[q]][0] + 1):
          print("leave:" + str(g_leave[T[q]][D[q]][i]))
          golem_count[g_leave[T[q]][D[q]][i] - 1] -= previous_golem_count[
              g_leave[T[q]][D[q]][i] - 1
          ]
      print(golem_count)
  print(N - golem_count[0] - golem_count[N + 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"}]