N,Q=map(int,input().split())
S=input()
move=[input().split() for i in range(Q)]
target=[m[0] for m in move]
d=[m[1] for m in move]

def check(i):
    now=i
    t=-1
    while True:
        if S[now] not in target[t+1:]:
            break
        t+=1+target[t+1:].index(S[now])
        if d[t]=="L":
            now-=1
        else:
            now+=1
        if now<0:
            return -1
        if now>=N:
            return 1
    return 0
Lmin=-1
Lmax=N
Rmin=-1
Rmax=N
C=[[1,2]]
while True:
    if len(C)==0:
        break
    c=C.pop()
    now=N*c[0]//c[1]
    x=check(now)
    if x==0:
        if Lmax>now:
            Lmax=now
            C.append([c[0]*2-1,c[1]*2])
        if Rmin<now:
            Rmin=now
            C.append([c[0]*2+1,c[1]*2])
    elif x==1:
        if now<Rmax:
            Rmax=now
            C.append([c[0]*2-1,c[1]*2])
    elif x==-1:
        if Lmin<now:
            Lmin=now
            C.append([c[0]*2+1,c[1]*2])
print(Rmax-Lmin-1)