import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
s = list(input())[: -1]
t = []
res = 0
for _ in range(Q):
  u, v = input().split()
  t.append((u, v))

def check(x):
  for i in range(Q):
    u, v = t[i]
    if s[x] == u:
      x += (-1) ** (v == "L")
    if x < 0:
      return -1
    if x >= N:
      return 1
  return 0

ok = -1
ng = N
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m) < 0:
    ok = m
  else: ng = m
res += ok + 1

ok = N
ng = -1
while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m) > 0:
    ok = m
  else: ng = m
res += N - ok
print(N - res)