N, Q = map(int, input().split())
s = input()
TD = [input().split() for i in range(Q)]


def simulate(n):
    if n == -1:
        return -1
    if n == N:
        return 1
    for t, d in TD:
        if t == s[n]:
            if d == "L":
                n -= 1
            else:
                n += 1
        if n == -1:
            return -1
        elif n == N:
            return 1
    return 0


l = -1
r = N
while l+1 < r:
    n = (l+r)//2
    sim = simulate(n)
    if sim == -1:
        l = n
    else:
        r = n
L = l

l = -1
r = N
while l+1 < r:
    n = (l+r)//2
    sim = simulate(n)
    if sim == 1:
        r = n
    else:
        l = n
R = r
print(R-L-1)
