N,q = gets.split.map(&:to_i)
S = "<#{gets.chomp}>"
Q = q.times.map{ gets.chomp }
L = Q.reverse_each.inject(0) do |pos, op|
  pos <= N && op[2] == 'L' && S[pos + 1] == op[0] ? pos + 1 : pos
end
R = Q.reverse_each.inject(N + 1) do |pos, op|
  pos > 0 && op[2] == 'R' && S[pos - 1] == op[0] ? pos - 1 : pos
end
puts [R - (L + 1), N].min
