N,q = gets.split.map(&:to_i)
S = "<#{gets.chomp}>"
Q = q.times.map{ gets.chomp }

def reach?(x, dist)
  Q.any? do |ops|
    x = (S[x] == ops[0] ? (ops[2] == 'L' ? (x - 1) : (x + 1)) : x)
    x == dist
  end
end

def unreach?(x, dist)
  !reach?(x, dist)
end

L = (0 .. N + 1).bsearch{|from| unreach?(from, 0) }
R = (L .. N + 1).bsearch{|from| reach?(from, N+1) }

puts R - L
