Integer N,Q
Character(1000000) moji
character(1),Allocatable,Dimension(:)::t,d
integer l,r
integer mi,ma,md
read*,N,Q
allocate(t(Q),d(Q))

read*,moji

do i=1,Q
  read*,t(i),d(i)
end do
!二部探索法、まずは0に落ちるもの
mi=0!辿り着く
ma=N+1!辿り着かないもの
Do while(mi+1<ma)
  md=(mi+ma)/2
  if( achievableLEFT(N,moji,Q,t,d,md) )then
    mi=md
  else
    ma=md
  end if
End do
l=md

!二部探索法N+1に落ちるもの
mi=0
ma=N+1
Do while(mi+1<ma)
  md=(mi+ma)/2
  if( achievableRIGHT(N,moji,Q,t,d,md) )then
    ma=md
  else
    mi=md
  end if
End do
r=ma

print"(i0)",r-l-1

contains
pure function achievableLEFT(N,moji,Q,t,d,md)
  Integer,intent(in)::N,Q
  Character(1000000),intent(in)::moji
  Character(1),intent(in)::t(1:Q),d(1:Q)
  Integer,intent(in)::md
  Integer soeji,i
  logical::achievableLEFT
  
  soeji=md
  do i=1,Q
    if (soeji==0 .or. soeji==N+1)EXIT
    if( moji(soeji:soeji) ==t(i) )then
      if(d(i)=="L")then
        soeji=soeji-1
      endif
      if(d(i)=="R")then
        soeji=soeji+1
      endif
    endif
  end do
  achievableLEFT=(soeji==0)
end function achievableLEFT
pure function achievableRIGHT(N,moji,Q,t,d,md)
  Integer,intent(in)::N,Q
  Character(1000000),intent(in)::moji
  Character(1),intent(in)::t(1:Q),d(1:Q)
  Integer,intent(in)::md
  Integer soeji,i
  logical::achievableRIGHT
  
  soeji=md
  do i=1,Q
    if (soeji==0 .or. soeji==N+1)EXIT
    if( moji(soeji:soeji) == t(i) )then
      if(d(i)=="L")then
        soeji=soeji-1
      endif
      if(d(i)=="R")then
        soeji=soeji+1
      endif
    endif
  end do
  achievableRight=(soeji==N+1)
end function achievableRIGHT
end