#include <iostream>
#include <vector>

using namespace std;

bool fall(string & b, int pos, int n, int q, vector<char> & qer){
    for(int i = 0; i < q; i++){
        if(pos == -1 || pos == n){
            return false;
        }
        if(qer[2*i] == b[pos]){
            if(qer[2*i+1] == 'L'){
                pos-=1;
            }
            else{
                pos+=1;
            }
        }
    }
    return true;
}

signed main(){
    int n, q;
    cin >> n >> q;
    vector<char> qer;
    string b;
    cin >> b;
    for(int i = 0; i < q; i++){
        char j, k;
        cin >> j >> k;
        qer.push_back(j);
        qer.push_back(k);
    }
    int l = -1;
    int r = n;
    while(r-l > 1){
        int mid = (l+r)/2;
        if(fall(b, mid, n, q, qer)){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    //cout << r;
    int ans = r;
    while(r-l > 1){
        int mid = (l+r)/2;
        if(fall(b, mid, n, q, qer)){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    //cout << r;
    ans += (n -r);
    int rans;
    rans = n - ans +1;
    cout >> rans;
}