import sys

input = sys.stdin.readline

N, Q = list(map(int, input().split()))

s = list(eval(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))
import sys

input = sys.stdin.readline

N, Q = list(map(int, input().split()))

S = list(eval(input()))[: -1]

qs = [input().split() for _ in range(Q)]



def lcheck(x):

  i = x

  for t, d in qs:

    if S[i] == t:

      if d == "L": i -= 1

      else: i += 1

    if i in range(N): continue

    return i < 0

  return False



def rcheck(x):

  i = x

  for t, d in qs:

    if S[i] == t:

      if d == "L": i -= 1

      else: i += 1

    if i in range(N): continue

    return i >= N

  return False



ok = -1

ng = N

while ng - ok > 1:

  m = (ok + ng) // 2

  if lcheck(m): ok = m

  else: ng = m



res = N - ng



ok = N

ng = -1

while ok - ng > 1:

  m = (ok + ng) // 2

  if rcheck(m): ok = m

  else: ng = m



res -= N - ok

print(res)
import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
s = list(eval(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))

import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
S = list(eval(input()))[:-1]
qs = [input().split() for _ in range(Q)]


def lcheck(x):
    i = x
    for t, d in qs:
        if S[i] == t:
            if d == "L":
                i -= 1
            else:
                i += 1
        if i in range(N):
            continue
        return i < 0
    return False


def rcheck(x):
    i = x
    for t, d in qs:
        if S[i] == t:
            if d == "L":
                i -= 1
            else:
                i += 1
        if i in range(N):
            continue
        return i >= N
    return False


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

-s = list(eval(input()))[:-1] -t = [] -res = 0 -for _ in range(Q): -    u, v = input().split() -    t.append((u, v)) +S = list(eval(input()))[:-1] +qs = [input().split() for _ in range(Q)] -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 +def lcheck(x): +    i = x +    for t, d in qs: +        if S[i] == t: +            if d == "L": +                i -= 1 +            else: +                i += 1 +        if i in range(N): +            continue +        return i < 0 +    return False + + +def rcheck(x): +    i = x +    for t, d in qs: +        if S[i] == t: +            if d == "L": +                i -= 1 +            else: +                i += 1 +        if i in range(N): +            continue +        return i >= N +    return False -    if check(m) < 0: +    if lcheck(m): -res += ok + 1 +res = N - ng -    if check(m) > 0: +    if rcheck(m): -res += N - ok -print((N - res)) +res -= N - ok +print(res)