def search_right(a, x, lo=0, hi=None, key=lambda x: x):

    if lo < 0:

        raise ValueError('lo must be non-negative')

    if hi is None:

        hi = len(a)

    while lo < hi:

        mid = (lo+hi)//2

        if x < key(a[mid]): hi = mid

        else: lo = mid+1

    return lo





def search_left(a, x, lo=0, hi=None, key=lambda x: x):

    if lo < 0:

        raise ValueError('lo must be non-negative')

    if hi is None:

        hi = len(a)

    while lo < hi:

        mid = (lo+hi)//2

        if key(a[mid]) < x: lo = mid+1

        else: hi = mid

    return lo





def get_fin_pos(s, td, golem_pos):

    for t, d in td:

        if 0 <= golem_pos < len(s) and s[golem_pos] == t:

            golem_pos += 1 if d == "R" else -1

    return golem_pos





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

s = "_{}_".format(eval(input()))

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



left = search_right(list(range(len(s))), 0, key=lambda golem: get_fin_pos(s, spells, golem))

right = search_left(list(range(len(s))), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem))



print((right - left))
n, q = list(map(int, input().split()))

s = "_{}_".format(eval(input()))

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



current_l = 0

current_r = len(s) - 1



for t, d in reversed(td):



    if current_l + 1 < len(s) - 1 and t == s[current_l + 1] and d == "L":

        current_l += 1

    elif t == s[current_l] and d == "R":

        current_l -= 1



    if 0 < current_r - 1 and t == s[current_r - 1] and d == "R":

        current_r -= 1

    elif t == s[current_r] and d == "L":

        current_r += 1



print((max(current_r - current_l - 1, 0)))

def search_right(a, x, lo=0, hi=None, key=lambda x: x):
    if lo < 0:
        raise ValueError("lo must be non-negative")
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]):
            hi = mid
        else:
            lo = mid + 1
    return lo


def search_left(a, x, lo=0, hi=None, key=lambda x: x):
    if lo < 0:
        raise ValueError("lo must be non-negative")
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


def get_fin_pos(s, td, golem_pos):
    for t, d in td:
        if 0 <= golem_pos < len(s) and s[golem_pos] == t:
            golem_pos += 1 if d == "R" else -1
    return golem_pos


n, q = list(map(int, input().split()))
s = "_{}_".format(eval(input()))
spells = [input().split() for _ in range(q)]
left = search_right(
    list(range(len(s))), 0, key=lambda golem: get_fin_pos(s, spells, golem)
)
right = search_left(
    list(range(len(s))), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem)
)
print((right - left))

n, q = list(map(int, input().split()))
s = "_{}_".format(eval(input()))
td = [input().split() for _ in range(q)]
current_l = 0
current_r = len(s) - 1
for t, d in reversed(td):
    if current_l + 1 < len(s) - 1 and t == s[current_l + 1] and d == "L":
        current_l += 1
    elif t == s[current_l] and d == "R":
        current_l -= 1
    if 0 < current_r - 1 and t == s[current_r - 1] and d == "R":
        current_r -= 1
    elif t == s[current_r] and d == "L":
        current_r += 1
print((max(current_r - current_l - 1, 0)))

-def search_right(a, x, lo=0, hi=None, key=lambda x: x): -    if lo < 0: -        raise ValueError("lo must be non-negative") -    if hi is None: -        hi = len(a) -    while lo < hi: -        mid = (lo + hi) // 2 -        if x < key(a[mid]): -            hi = mid -        else: -            lo = mid + 1 -    return lo - - -def search_left(a, x, lo=0, hi=None, key=lambda x: x): -    if lo < 0: -        raise ValueError("lo must be non-negative") -    if hi is None: -        hi = len(a) -    while lo < hi: -        mid = (lo + hi) // 2 -        if key(a[mid]) < x: -            lo = mid + 1 -        else: -            hi = mid -    return lo - - -def get_fin_pos(s, td, golem_pos): -    for t, d in td: -        if 0 <= golem_pos < len(s) and s[golem_pos] == t: -            golem_pos += 1 if d == "R" else -1 -    return golem_pos - - -spells = [input().split() for _ in range(q)] -left = search_right( -    list(range(len(s))), 0, key=lambda golem: get_fin_pos(s, spells, golem) -) -right = search_left( -    list(range(len(s))), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem) -) -print((right - left)) +td = [input().split() for _ in range(q)] +current_l = 0 +current_r = len(s) - 1 +for t, d in reversed(td): +    if current_l + 1 < len(s) - 1 and t == s[current_l + 1] and d == "L": +        current_l += 1 +    elif t == s[current_l] and d == "R": +        current_l -= 1 +    if 0 < current_r - 1 and t == s[current_r - 1] and d == "R": +        current_r -= 1 +    elif t == s[current_r] and d == "L": +        current_r += 1 +print((max(current_r - current_l - 1, 0)))