#include <iostream>
#include <cstdlib>
#include <string>
#include <set>
#include <vector>

using namespace std;

int n,q;
string str;
vector<pair<char, char> > req;

int judge(int x){
	for(auto &p: req){
		if(str[x] == p.first){
			if(p.second == 'L'){
				x--;
				if(x == -1)return 1;
			}else{
				x++;
				if(x == n)return -1;
			}
		}
	}
	return 0;
}

int main()
{
	cin >> n >> q;
	cin >> str;
	
	for(int i = 0 ; i < q; i++){
		char X;
		cin >> X;
		char lr;
		cin >> lr;
		req.push_back(make_pair(X, lr));
	}
	
	int l = 0, r = n;
	int m = (l + r) / 2;
	while(1){
		if(judge(m) > 0){
			l = m;
		}else{
			r = m;
		}
		m = (l + r) / 2;
		if(r - l == 1){
			break;
		}
	}
	//cout << r << endl;
	int start = r;
	
	l = 0, r = n;
	m = (l + r) / 2;
	while(1){
		if(judge(m) < 0){
			r = m;
		}else{
			l = m;
		}
		m = (l + r) / 2;
		if(r - l == 1){
			break;
		}
	}
	cout << r - start << endl;
}