# -*- coding: utf-8 -*-

n,q = list(map(int, input().split()))

s = eval(input())

td = [input().split() for _ in range(q)]



def check(idx, x):

    for t,d in td:

        if idx==x:

            return True

        elif idx==n or idx==-1:

            return False



        if s[idx]==t:

            if d=="L":

                idx -= 1

            else:

                idx += 1

    return idx==x



ok = -1

ng = n

while abs(ok-ng)>1:

    mid = (ok+ng)//2

    if check(mid, -1):

        ok = mid

    else:

        ng = mid

res = ok+1



ok = n

ng = -1

while abs(ok-ng)>1:

    mid = (ok+ng)//2

    if check(mid, n):

        ok = mid

    else:

        ng = mid

res += n-ok



print((n-res))

# -*- coding: utf-8 -*-

n,q = list(map(int, input().split()))

s = eval(input())

td = [input().split() for _ in range(q)]



l = 0

r = n - 1

for i in range(q-1,-1,-1):

    t,d = td[i]



    if n>l>=0:

        if s[l]==t and d=="L":

            l += 1

        elif l>0 and s[l-1]==t and d=="R":

            l -= 1



    if n>r>=0:

        if s[r]==t and d=="R":

            r -= 1

        elif r<n-1 and s[r+1]==t and d=="L":

            r += 1



print((n - l - (n-1-r)))

# -*- coding: utf-8 -*-
n, q = list(map(int, input().split()))
s = eval(input())
td = [input().split() for _ in range(q)]


def check(idx, x):
    for t, d in td:
        if idx == x:
            return True
        elif idx == n or idx == -1:
            return False
        if s[idx] == t:
            if d == "L":
                idx -= 1
            else:
                idx += 1
    return idx == x


ok = -1
ng = n
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if check(mid, -1):
        ok = mid
    else:
        ng = mid
res = ok + 1
ok = n
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if check(mid, n):
        ok = mid
    else:
        ng = mid
res += n - ok
print((n - res))

# -*- coding: utf-8 -*-
n, q = list(map(int, input().split()))
s = eval(input())
td = [input().split() for _ in range(q)]
l = 0
r = n - 1
for i in range(q - 1, -1, -1):
    t, d = td[i]
    if n > l >= 0:
        if s[l] == t and d == "L":
            l += 1
        elif l > 0 and s[l - 1] == t and d == "R":
            l -= 1
    if n > r >= 0:
        if s[r] == t and d == "R":
            r -= 1
        elif r < n - 1 and s[r + 1] == t and d == "L":
            r += 1
print((n - l - (n - 1 - r)))

- - -def check(idx, x): -    for t, d in td: -        if idx == x: -            return True -        elif idx == n or idx == -1: -            return False -        if s[idx] == t: -            if d == "L": -                idx -= 1 -            else: -                idx += 1 -    return idx == x - - -ok = -1 -ng = n -while abs(ok - ng) > 1: -    mid = (ok + ng) // 2 -    if check(mid, -1): -        ok = mid -    else: -        ng = mid -res = ok + 1 -ok = n -ng = -1 -while abs(ok - ng) > 1: -    mid = (ok + ng) // 2 -    if check(mid, n): -        ok = mid -    else: -        ng = mid -res += n - ok -print((n - res)) +l = 0 +r = n - 1 +for i in range(q - 1, -1, -1): +    t, d = td[i] +    if n > l >= 0: +        if s[l] == t and d == "L": +            l += 1 +        elif l > 0 and s[l - 1] == t and d == "R": +            l -= 1 +    if n > r >= 0: +        if s[r] == t and d == "R": +            r -= 1 +        elif r < n - 1 and s[r + 1] == t and d == "L": +            r += 1 +print((n - l - (n - 1 - r)))