PROGRAM ATCODER

implicit none
integer :: n,q,out=0,i,j
character(len=2*10**5) :: s,s_l='',s_r=''
integer,allocatable :: g(:) !g(:)はゴーレムの数
character(len=1),allocatable :: d(:),t(:)

read*, n,q,s
allocate(t(q),d(q),g(n))
do i = 1, q, 1
  read*, t(i),d(i)
end do

g = 1
do i = 1, q, 1
    if ( t(i) == s(1:1) .and. d(i) == 'L' ) then
      out =  out + g(1)
      g(1) = 0
    else if ( t(i) == s(n:n) .and. d(i) == 'R' ) then
      out = out + g(n)
      g(n) = 0
    end if
    do j = 1, n
      if ( t(i) == s(j:j) ) then
        if ( d(i) == 'L' ) then
          g(j-1) = g(j-1) + g(j)
          g(j) = 0
        else
          g(j+1) = g(j+1) + g(j)
          g(j) = 0
        end if
      end if
    end do
end do

print'(i0)', n-out

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER
