import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,q = map(int,input().split())
s = input().strip()
a = [list(input().split()) for i in range(q)]
def cheak(x):
  for i in range(q):
      if s[x] == a[i][0]:
          if a[i][1] == "L":
              x-=1
          else:
              x+=1
      if x >= n :
          return 0
      elif x < 0:
          return 1
  return 0
def cheak2(x):
  for i in range(q):
      if s[x] == a[i][0]:
          if a[i][1] == "L":
              x-=1
          else:
              x+=1
      if x >= n :
          return 1
      elif x < 0:
          return 0
  return 0
dai = n-1
syo = 0
hi = cheak(syo)
mi = cheak2(dai)
if hi== 0 and mi==0:
    print(n)
elif hi and mi:
  while True:
    if dai-syo <= 1:
        if cheak(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak(kon)
    if c == 0:
        dai = kon
    else:
        syo = kon
  ab = dai
  dai = n-1
  syo = 0
  while True:
    if dai-syo <= 1:
        if cheak2(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak2(kon)
    if c == 1:
        dai = kon
    else:
        syo = kon
  if dai <= ab:
      print(0)
      exit()
  print(n-(ab+1+n-dai))
elif hi==1 and mi == 0:
  while True:
    if dai-syo <= 1:
        if cheak(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak(kon)
    if c == 0:
        dai = kon
    else:
        syo = kon
  print(n-1-dai)
else:
  while True:
    if dai-syo <= 1:
        if cheak2(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak2(kon)
    if c == 1:
        dai = kon
    else:
        syo = kon
  print(syo+1)