### BUGGY CODE ###

import sys
input=sys.stdin.readline
N,Q=map(int,input().split())
s=input()
move=[tuple(input().split()) for i in range(Q)]
inf=float('inf')
alive=[inf,-1*inf]
dead=[-1*inf,inf]
def check(i):
    now=i
    for j in range(Q):
        if move[j][0]==s[now]:
            if move[j][1]=='L':
                now-=1
            elif move[j][1]=='R':
                now+=1
        if now<0:
            return 'left'
        if now>N-1:
            return 'right'
    return 'alive'
from collections import deque
search=deque([(1,2)])
while len(search)>0:
    if dead[0]+1==alive[0] and dead[1]-1==alive[1] or dead[0]+1==dead[1]:
        break
    now=search.popleft()
    idx=now[0]*N//now[1]
    res=check(idx)
    if res=='alive':
        if alive[0]>alive[1]:
            alive=[idx,idx]
            search.append((2*now[0]-1,2*now[1]))
            search.append((2*now[0]+1,2*now[1]))
        elif idx<alive[0]:
            alive[0]=idx
            if alive[0]-1==dead[0]:
                continue
            search.append((2*now[0]-1,2*now[1]))
        elif idx>alive[1]:
            alive[1]=idx
            if alive[1]+1==dead[1]:
                continue
            search.append((2*now[0]+1,2*now[1]))
        elif idx==0 or idx==N-1:
            continue
    elif res=='left':
        if idx>dead[0]:
            dead[0]=idx
            if dead[0]+1==alive[0]:
                continue
            search.append((2*now[0]+1,2*now[1]))
    elif res=='right':
        if idx<dead[1]:
            dead[1]=idx
            if dead[1]-1==alive[1]:
                continue
            search.append((2*now[0]-1,2*now[1]))
if alive[0]>alive[1]:
    print(0)
else:
    print(alive[1]-alive[0]+1)

### FIXED CODE ###

import sys
input=sys.stdin.readline
N,Q=map(int,input().split())
s=input()
move=[input().split() for i in range(Q)]
inf=float('inf')
alive=[inf,-1*inf]
dead=[-1*inf,inf]
def check(i):
    now=i
    for m in move:
        if m[0]==s[now]:
            if m[1]=='L':
                now-=1
            elif m[1]=='R':
                now+=1
        if now<0:
            return 'left'
        if now>N-1:
            return 'right'
    return 'alive'
def search(now,alive,dead):
    if dead[0]+1==alive[0] and dead[1]-1==alive[1] or dead[0]+1==dead[1]:
        return alive,dead
    idx=now[0]*N//now[1]
    res=check(idx)
    if res=='alive':
        if alive[0]>alive[1]:
            alive=[idx,idx]
            alive,dead=search((2*now[0]-1,2*now[1]),alive,dead)
            alive,dead=search((2*now[0]+1,2*now[1]),alive,dead)
        elif idx<alive[0]:
            alive[0]=idx
            if alive[0]-1!=dead[0]:
                alive,dead=search((2*now[0]-1,2*now[1]),alive,dead)
        elif idx>alive[1]:
            alive[1]=idx
            if alive[1]+1!=dead[1]:
                alive,dead=search((2*now[0]+1,2*now[1]),alive,dead)
        elif idx==0 or idx==N-1:
            return alive,dead
    elif res=='left':
        if idx>dead[0]:
            dead[0]=idx
            if dead[0]+1!=alive[0]:
                alive,dead=search((2*now[0]+1,2*now[1]),alive,dead)
    elif res=='right':
        if idx<dead[1]:
            dead[1]=idx
            if dead[1]-1!=alive[1]:
                alive,dead=search((2*now[0]-1,2*now[1]),alive,dead)
    return alive,dead
alive,dead=search((1,2),alive,dead)
if alive[0]>alive[1]:
    print(0)
else:
    print(alive[1]-alive[0]+1)