#include<bits/stdc++.h>
using namespace std;
const int mx = 200005;
int n, q, l, r, a[2];
char s[mx], t1, t2;
pair<char, bool> p[mx];

bool C(int now, bool left){
    for(int i = 0; i < q; i++){
        if(p[i].first == s[now]){
            if(now == 0 && p[i].second) return !left;
            if(now == n-1 && !(p[i].second)) return left;
            now += p[i].second ? -1 : 1;
        }
    }
    return true;
}
int main(){
    scanf("%d%d%s\n", &n, &q, s);
    for(int i = 0; i < q; i++){
        scanf("%c %c\n", &t1, &t2);
        p[i] = make_pair(t1, t2 == 'L');
    }
    for(int i = 0; i < 2; i++){
        l = -1; r = n;
        while(l+1 < r){
            int mid = (l+r) / 2;
            (C(mid, i == 0)^(i == 0) ? l : r) = mid;
        }
        a[i] = r;
    }
    printf("%d\n", a[1] - a[0]);
}