N, Q = gets.chomp.split(' ').map(&:to_i)
S = gets.chomp
SPELL_LIST = Q.times.map { gets.chomp.split(' ') }

def last_position(i)
  pos = i
  dropped_pos = nil
  SPELL_LIST.each do |t, d|
    ch = S[pos]
    next unless t == ch
    if d == 'L'
      pos -= 1
    else
      pos += 1
    end
    if pos < 0
      ret = -1
      break
    elsif pos > N - 1
      ret = N
      break
    end
  end
  dropped_pos || pos
end

def left_edge_pos
  (0...N).to_a.bsearch do |i|
    last_position(i) >= 0
  end
end

def right_first_dropped_pos
  (0...N).to_a.bsearch do |i|
    last_position(i) == N
  end
end

ans = (right_first_dropped_pos || N) - (left_edge_pos || 0)
puts ans
