output_description: If there exists an equilateral triangle whose sides have lengths A, B and C,
  print `Yes`; otherwise, print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A B C
attempt: # coding: utf-8
  def main():
      N, Q = map(int, input().split())
      s = input()
      ans = N
      command = []
  
      # print(char_list)
  
      for i in range(Q):
          t, d = input().split()
          command.append([t, d])
  
      r = binary_serch_R(command, s, N)
      # print(r)
      l = binary_serch_L(command, s, N)
      # print(l)
      ans = ans - (N - r) - (l + 1)
      if ans < 0:
          ans = 0
      print(ans)
  
  
  def simulation_R(command, s, now, N):
      for pair in command:
          if pair[0] == s[now]:
              if pair[1] == "L":
                  now -= 1
              elif pair[1] == "R":
                  now += 1
          if now < 0:
              return False
          elif now >= N:
              return True
      return False
  
  
  def simulation_L(command, s, now, N):
      for pair in command:
          if pair[0] == s[now]:
              if pair[1] == "L":
                  now -= 1
              elif pair[1] == "R":
                  now += 1
          if now < 0:
              return True
          elif now >= N:
              return False
      return False
  
  
  def binary_serch_R(command, s, N):
      left = 0
      right = N - 1
      if simulation_R(command, s, left, N):
          return -1
      if simulation_R(command, s, right, N) == False:
          return N
  
      while abs(right - left) > 1:
          mid = int((left + right) / 2)
          # print(mid)
          if simulation_R(command, s, mid, N):
              right = mid
          else:
              left = mid
      return right
  
  
  def binary_serch_L(command, s, N):
      left = 0
      right = N - 1
      if simulation_L(command, s, left, N) == False:
          return -1
      if simulation_L(command, s, right, N):
          return N
  
      while abs(right - left) > 1:
          mid = int((left + right) / 2)
          if simulation_L(command, s, mid, N):
              left = mid
          else:
              right = mid
      return left
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  You are given three integers A, B and C.
  
  Determine if there exists an equilateral triangle whose sides have lengths A,
  B and C.
samples: [{"input": "2 2 2", "output": "Yes\n    \n\n  * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n    \n\n  * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}]