n, q = map(int, input().split())
s = input()
td = [input().split() for _ in range(q)]


def sim(i):
    if i == -1:
        return -1
    if i == n:
        return 1
    for t, d in td:
        if t == s[i]:
            if d == 'L':
                i -= 1
            else:
                i += 1
        if i == -1:
            return -1
        if i == n:
            return 1
    return 0


l =-1
r = n
while l + 1 < r:
    m = (l + r) // 2
    if sim(m) == -1:
        l = m
    else:
        r = m
A = l

l = -1
r = n
while l + 1 < r:
    m = (l + r) // 2
    if sim(m) == 1:
        r = m
    else:
        l = m
B = r

print(B - A - 1)