n, q = map(int, input().split())
s = input()
pair = [input().split() for _ in range(q)]
# 場所
lst = list(set(s))
pair = [i for i in pair if i[0] in lst]
# 初期位置(0スタート)
place = dict([(l, []) for l in lst])
for i, j in enumerate(s):
    place[j].append(i)
# 端
edge = [s[0], s[-1]]
# print(init)
# 座標
grid = [1]*n
# 移動
for i, j in pair:
    index = place[i]
    tmp = [grid[k] for k in index]
    for k in index:
        grid[k] = 0
    if j == 'L':
        new_index = index[1:] if i == edge[0] else index
        new_tmp = tmp[1:] if i == edge[0] else tmp
        for k, t in zip(new_index, new_tmp):
            grid[k - 1] += t
    else:
        new_index = index[:-1] if i == edge[1] else index
        new_tmp = tmp[:-1] if i == edge[1] else tmp
        for k, t in zip(new_index, new_tmp):
            grid[k + 1] += t
# 処理
print(sum(grid))