#include<bits/stdc++.h>
#define N 500005

using namespace std;

int n,m;char s[N],ss[N][2],op[N][2];

inline bool check(int x,int y){
    for (int i=1;i<=m;i++){
        if (s[x]==ss[i][1]){
            if (op[i][1]=='L') x--;
            else x++;
        }
    }
    return x==y;
}

int main(){
    scanf("%d%d",&n,&m);
    scanf("%s",s+1);
    for (int i=1;i<=m;i++){
        scanf("%s",ss[i]+1);
        scanf("%s",op[i]+1);
    }int ans=n;
    int l=1;int r=n;
    int L=1;int R=n;
    while (l+1<r){
        int mid=(l+r)>>1;
        if (check(mid,0)) l=mid;
        else r=mid;
    }
    if (check(r,0)) ans-=r;
    else if (check(l,0)) ans-=l;
    while (L+1<R){
        int mid=(L+R)>>1;
        if (check(mid,n+1)) R=mid;
        else L=mid;
    }
    if (check(L,n+1)) ans-=n-L+1;
    else if (check(R,n+1)) ans-=n-R+1;
    printf("%d\n",ans);
    return 0;
}