def simulate(n):
    p=n
    if memo[n]!=-1: return memo[n]
    if n==-1: return 0
    if n==N: return 2
    
    for i in range(Q):
        if TD[i][0]==s[n]:
            if TD[i][1]=="R": n+=1
            if TD[i][1]=="L": n-=1

        if n<0 :
            memo[p]=0
            return 0
        elif n>=N:
            memo[p]=2
            return 2 
    memo[p]=1
    return 1

N, Q = map(int, input().split())
s = input()
TD = [input().split() for i in range(Q)]
memo=[-1]*N


low = 0
high =N-1
# t は中央番目の数
t =int((low+high)/2) 

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかったということ
while (1):
    if simulate(t) in [0,1] and simulate(t+1)==2:
        break
    elif simulate(t) in [0,1]:
        low = t+1
    elif simulate(t)==2:
        high = t-1
    t = int((low + high) / 2)


R=t

low = 0
high =N-1
# t は中央番目の数
t =int((low+high)/2) 

while (1):
    if simulate(t-1)==0 and simulate(t) in [1,2]:
        break
    elif simulate(t)==0:
        low = t+1
    elif simulate(t) in [1,2]:
        high = t-1
    t = int((low + high) / 2)

L=t

print(R-L+1)
print(memo)