N,Q=list(map(int,input().split()))

S='.'+eval(input())+'.'



TD=[]

for i in range(Q):

    t, d = input().split()

    if d=='L':

        TD.append([t,-1])

    else:

        TD.append([t,1])



def check(place):

    for i in range(Q):

        td=TD[i]

        if td[0]!=S[place]:

            continue

        else:

            place+=td[1]



        if place<=0:

            return -1

        if place>=N+1:

            return 1

    return 0



l,r=0,N+1

L,R=0,N+1



while abs(r-l)>1:

    m=(l+r)//2

    if check(m)<0:

        l=m

    else:

        r=m

L=l

l,r=0,N+1



while abs(r-l)>1:

    m=(l+r)//2

    if check(m)>0:

        r=m

    else:

        l=m



R=r



print((max(R-L-1,0)))

N,Q=list(map(int,input().split()))

S=eval(input())



TD=[]

for i in range(Q):

    t, d = input().split()

    if d=='L':

        TD.append([t,-1])

    else:

        TD.append([t,1])



def check(place):

    for td in TD:

        if td[0]==S[place]:

            place+=td[1]

            if place<0:

                return -1

            elif place>=N:

                return 1

    return 0



l,r=-1,N

L,R=-1,N



while abs(r-l)>1:

    m=(l+r)//2

    if check(m)<0:

        l=m

    else:

        r=m

L=l

l,r=-1,N



while abs(r-l)>1:

    m=(l+r)//2

    if check(m)>0:

        r=m

    else:

        l=m



R=r



print((max(R-L-1,0)))

N, Q = list(map(int, input().split()))
S = "." + eval(input()) + "."
TD = []
for i in range(Q):
    t, d = input().split()
    if d == "L":
        TD.append([t, -1])
    else:
        TD.append([t, 1])


def check(place):
    for i in range(Q):
        td = TD[i]
        if td[0] != S[place]:
            continue
        else:
            place += td[1]
        if place <= 0:
            return -1
        if place >= N + 1:
            return 1
    return 0


l, r = 0, N + 1
L, R = 0, N + 1
while abs(r - l) > 1:
    m = (l + r) // 2
    if check(m) < 0:
        l = m
    else:
        r = m
L = l
l, r = 0, N + 1
while abs(r - l) > 1:
    m = (l + r) // 2
    if check(m) > 0:
        r = m
    else:
        l = m
R = r
print((max(R - L - 1, 0)))

N, Q = list(map(int, input().split()))
S = eval(input())
TD = []
for i in range(Q):
    t, d = input().split()
    if d == "L":
        TD.append([t, -1])
    else:
        TD.append([t, 1])


def check(place):
    for td in TD:
        if td[0] == S[place]:
            place += td[1]
            if place < 0:
                return -1
            elif place >= N:
                return 1
    return 0


l, r = -1, N
L, R = -1, N
while abs(r - l) > 1:
    m = (l + r) // 2
    if check(m) < 0:
        l = m
    else:
        r = m
L = l
l, r = -1, N
while abs(r - l) > 1:
    m = (l + r) // 2
    if check(m) > 0:
        r = m
    else:
        l = m
R = r
print((max(R - L - 1, 0)))

-S = "." + eval(input()) + "." +S = eval(input()) -    for i in range(Q): -        td = TD[i] -        if td[0] != S[place]: -            continue -        else: +    for td in TD: +        if td[0] == S[place]: -        if place <= 0: -            return -1 -        if place >= N + 1: -            return 1 +            if place < 0: +                return -1 +            elif place >= N: +                return 1 -l, r = 0, N + 1 -L, R = 0, N + 1 +l, r = -1, N +L, R = -1, N -l, r = 0, N + 1 +l, r = -1, N