#include<bits/stdtr1c++.h>
using namespace std;

char j[1000001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	memset(j, 'n', sizeof(j));
	map < char, int > c2i;
	c2i['S'] = 1;
	c2i['M'] = 2;
	c2i['L'] = 3;
	int J, a; cin >> J >> a;
	for (int i = 0; i < J; ++i){
		char ji; cin >> ji;
		j[i] = ji;
	}
	int t = 0;
	for (int i = 0; i < a; ++i){
		char si; int ji; cin >> si >> ji;
		if (j[ji - 1] != 'n')
			if (c2i[j[ji - 1]] >= c2i[si]){
				++t;
				j[ji - 1] = 'n';
			}
	}
	cout << t << endl;
	return 0;
}