import sys

input = sys.stdin.readline



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

S = input().rstrip()

TD = [list(map(str, input().split())) for _ in range(Q)]



l = 0

r = N

while r - l > 1:

    m = (l+r)//2

    right_over = False

    pl = m

    for t, d in TD:

        if S[pl] == t:

            if d == 'L':

                pl -= 1

                if pl == -1:

                    break

            else:

                pl += 1

                if pl == N:

                    right_over = True

                    break

    if right_over:

        r = m

    else:

        l = m



right = l



l = 0

r = N

while r - l > 1:

    m = (l+r)//2

    left_over = False

    pl = m

    for t, d in TD:

        if S[pl] == t:

            if d == 'L':

                pl -= 1

                if pl == -1:

                    left_over = True

                    break

            else:

                pl += 1

                if pl == N:

                    break

    if left_over:

        l = m

    else:

        r = m



left = l



print((right-left))
import sys

input = sys.stdin.readline



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

S = input().rstrip()

Query = []

for _ in range(Q):

    Alp, LR = list(map(str, input().rstrip().split()))

    Query.append((Alp, LR))



S = "a" + S + "a"



left = 1

for Alp, LR in reversed(Query):

    if S[left-1] == Alp and LR == "R":

        left -= 1

    elif S[left] == Alp and LR == "L":

        left += 1



right = 1

for Alp, LR in reversed(Query):

    if S[-right] == Alp and LR == "L":

        right -= 1

    elif S[-1-right] == Alp and LR == "R":

        right += 1



print((max(0, N+2-left-right)))
import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
S = input().rstrip()
TD = [list(map(str, input().split())) for _ in range(Q)]
l = 0
r = N
while r - l > 1:
    m = (l + r) // 2
    right_over = False
    pl = m
    for t, d in TD:
        if S[pl] == t:
            if d == "L":
                pl -= 1
                if pl == -1:
                    break
            else:
                pl += 1
                if pl == N:
                    right_over = True
                    break
    if right_over:
        r = m
    else:
        l = m
right = l
l = 0
r = N
while r - l > 1:
    m = (l + r) // 2
    left_over = False
    pl = m
    for t, d in TD:
        if S[pl] == t:
            if d == "L":
                pl -= 1
                if pl == -1:
                    left_over = True
                    break
            else:
                pl += 1
                if pl == N:
                    break
    if left_over:
        l = m
    else:
        r = m
left = l
print((right - left))

import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
S = input().rstrip()
Query = []
for _ in range(Q):
    Alp, LR = list(map(str, input().rstrip().split()))
    Query.append((Alp, LR))
S = "a" + S + "a"
left = 1
for Alp, LR in reversed(Query):
    if S[left - 1] == Alp and LR == "R":
        left -= 1
    elif S[left] == Alp and LR == "L":
        left += 1
right = 1
for Alp, LR in reversed(Query):
    if S[-right] == Alp and LR == "L":
        right -= 1
    elif S[-1 - right] == Alp and LR == "R":
        right += 1
print((max(0, N + 2 - left - right)))

-TD = [list(map(str, input().split())) for _ in range(Q)] -l = 0 -r = N -while r - l > 1: -    m = (l + r) // 2 -    right_over = False -    pl = m -    for t, d in TD: -        if S[pl] == t: -            if d == "L": -                pl -= 1 -                if pl == -1: -                    break -            else: -                pl += 1 -                if pl == N: -                    right_over = True -                    break -    if right_over: -        r = m -    else: -        l = m -right = l -l = 0 -r = N -while r - l > 1: -    m = (l + r) // 2 -    left_over = False -    pl = m -    for t, d in TD: -        if S[pl] == t: -            if d == "L": -                pl -= 1 -                if pl == -1: -                    left_over = True -                    break -            else: -                pl += 1 -                if pl == N: -                    break -    if left_over: -        l = m -    else: -        r = m -left = l -print((right - left)) +Query = [] +for _ in range(Q): +    Alp, LR = list(map(str, input().rstrip().split())) +    Query.append((Alp, LR)) +S = "a" + S + "a" +left = 1 +for Alp, LR in reversed(Query): +    if S[left - 1] == Alp and LR == "R": +        left -= 1 +    elif S[left] == Alp and LR == "L": +        left += 1 +right = 1 +for Alp, LR in reversed(Query): +    if S[-right] == Alp and LR == "L": +        right -= 1 +    elif S[-1 - right] == Alp and LR == "R": +        right += 1 +print((max(0, N + 2 - left - right)))