def sim(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
        if n == N:
            return 1
    return 0

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

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

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

print(R-L-1)