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

S = ' ' + eval(input()) + ' '



ps = [0, N+1]

dirs = { 'L': -1, 'R': 1 }

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

def drop(p):

  for t, d in QS:

    if S[p] == t:

      p = p + dirs[d]

      if p == 0 or p == N+1:

        return 1 if p == N+1 else -1

  return 0



# 二分探索

f = 0

t = N+1

while f + 1 < t:

  mid = f + (t-f)//2

  ret = drop(mid)

  if ret != -1:

    t = mid

  else:

    f = mid

p1 = f



f = 0

t = N+1

while f + 1 < t:

  mid = f + (t-f)//2

  ret = drop(mid)

  if ret == 1:

    t = mid

  else:

    f = mid

p2 = f

print((max(0, p2-p1)))
N, Q = list(map(int, input().split()))

S = ' ' + eval(input()) + ' '



ps = [0, N+1]

dirs = { 'L': 1, 'R': -1 }

QS = [input().split() for _ in range(Q)][::-1]

p = 0

for t, d in QS:

  di = dirs[d]

  np = p + di

  if 0 <= np <= N+1 and di == 1 and S[np] == t:

    p += 1

  if 0 <= np <= N+1 and di == -1 and S[p] == t:

    p -= 1

p1 = p



p = N+1

for t, d in QS:

  di = dirs[d]

  np = p + di

  if 0 <= np <= N+1 and di == -1 and S[np] == t:

    p -= 1

  if 0 <= np <= N+1 and di == 1 and S[p] == t:

    p += 1

p2 = p

print((max(0, p2 - p1 - 1)))
N, Q = list(map(int, input().split()))
S = " " + eval(input()) + " "
ps = [0, N + 1]
dirs = {"L": -1, "R": 1}
QS = [input().split() for _ in range(Q)]


def drop(p):
    for t, d in QS:
        if S[p] == t:
            p = p + dirs[d]
            if p == 0 or p == N + 1:
                return 1 if p == N + 1 else -1
    return 0


# 二分探索
f = 0
t = N + 1
while f + 1 < t:
    mid = f + (t - f) // 2
    ret = drop(mid)
    if ret != -1:
        t = mid
    else:
        f = mid
p1 = f
f = 0
t = N + 1
while f + 1 < t:
    mid = f + (t - f) // 2
    ret = drop(mid)
    if ret == 1:
        t = mid
    else:
        f = mid
p2 = f
print((max(0, p2 - p1)))

N, Q = list(map(int, input().split()))
S = " " + eval(input()) + " "
ps = [0, N + 1]
dirs = {"L": 1, "R": -1}
QS = [input().split() for _ in range(Q)][::-1]
p = 0
for t, d in QS:
    di = dirs[d]
    np = p + di
    if 0 <= np <= N + 1 and di == 1 and S[np] == t:
        p += 1
    if 0 <= np <= N + 1 and di == -1 and S[p] == t:
        p -= 1
p1 = p
p = N + 1
for t, d in QS:
    di = dirs[d]
    np = p + di
    if 0 <= np <= N + 1 and di == -1 and S[np] == t:
        p -= 1
    if 0 <= np <= N + 1 and di == 1 and S[p] == t:
        p += 1
p2 = p
print((max(0, p2 - p1 - 1)))

-dirs = {"L": -1, "R": 1} -QS = [input().split() for _ in range(Q)] - - -def drop(p): -    for t, d in QS: -        if S[p] == t: -            p = p + dirs[d] -            if p == 0 or p == N + 1: -                return 1 if p == N + 1 else -1 -    return 0 - - -# 二分探索 -f = 0 -t = N + 1 -while f + 1 < t: -    mid = f + (t - f) // 2 -    ret = drop(mid) -    if ret != -1: -        t = mid -    else: -        f = mid -p1 = f -f = 0 -t = N + 1 -while f + 1 < t: -    mid = f + (t - f) // 2 -    ret = drop(mid) -    if ret == 1: -        t = mid -    else: -        f = mid -p2 = f -print((max(0, p2 - p1))) +dirs = {"L": 1, "R": -1} +QS = [input().split() for _ in range(Q)][::-1] +p = 0 +for t, d in QS: +    di = dirs[d] +    np = p + di +    if 0 <= np <= N + 1 and di == 1 and S[np] == t: +        p += 1 +    if 0 <= np <= N + 1 and di == -1 and S[p] == t: +        p -= 1 +p1 = p +p = N + 1 +for t, d in QS: +    di = dirs[d] +    np = p + di +    if 0 <= np <= N + 1 and di == -1 and S[np] == t: +        p -= 1 +    if 0 <= np <= N + 1 and di == 1 and S[p] == t: +        p += 1 +p2 = p +print((max(0, p2 - p1 - 1)))