program main
  implicit none
  integer :: N ,Q
  character(len=200000) :: S
  integer,allocatable:: g(:),g_bf(:)
  logical,allocatable:: flag(:)
  character (len=1),allocatable :: t(:)
  character (len=1),allocatable :: d(:)
  integer :: i,j
  read(*,*) N,Q
  read(*,'(A)') S(1:N)
  allocate(t(Q),d(Q))
  allocate(g(N))
  allocate(g_bf(N))
  allocate(flag(N))
  g=1
  do i = 1,Q
     read(*,'(A,1x,A)') t(i),d(i)
  end do

  do i = 1,Q
     g_bf = g
     do j = 1,N
        if (s(j:j) == t(i))then
           if (d(i) == 'L') then
              g(j) = g(j) - g_bf(j)
              if (j /= 0)   g(j-1) = g(j-1) + g_bf(j)
           else
              g(j) = g(j) - g_bf(j)
              if (j /= N) g(j+1) = g(j+1) + g_bf(j)
           end if
        end if
     end do
     !where(g<0) g=0
  end do
  write(*,'(i0)') sum(g)
  stop
end program main
