n_q = gets.split(" ") # 3 4
block_numbers = n_q[0].to_i # 3
jumon_times = n_q[1].to_i # 4

block_strings = gets.chomp! # ABC
block_strings = block_strings.split("") # ['A', 'B', 'C']

all_jumon = []
for i in 1..jumon_times do
    jumon = gets.split("")
    all_jumon << jumon # [['A', 'L'], ['B', 'R']]
end

all_jumon_count = all_jumon.count - 1
gorem = block_strings.count

for i in 0..all_jumon_count do
    jumon = all_jumon[i] # A Ls
    block_number = jumon[0]
    move = jumon[2]
    if (block_strings[0] == block_number && move == "L") || (block_strings[-1] == block_number && move == "R")
        gorem -= 1
    end
end

puts gorem