```#include <bits/stdc++.h>

using namespace std;
// Constants and macros
#define INF 		(int)1e9
#define EPS 		1e-9
#define bitcount 	__builtin_popcount
#define gcd 		__gcd
#define forall(i,a,b) 	for(int i=a;i<b;i++)
#define pb 		push_back
#define mp		make_pair
#define MAX(a,b)	( (a)>(b) ? (a):(b))
#define MIN(a,b)	( (a)<(b) ? (a):(b))
#define s(a)		scanf("%d", &a)
#define ss(a,b)		scanf("%d %d", &a,&b)
#define sss(a,b,c)	scanf("%d %d %d", &a,&b,&c)
#define sl(a)		scanf("%I64d", &a)

int J, A, jer;
string S;
int jersey[1000002];
unordered_map<int,int> T;

int main(){
s(J);
s(A);
forall(i,0,J){
cin >> S;
if (S[0] == 'S') jersey[i] =1;
if (S[0] == 'M') jersey[i] =2;
if (S[0] == 'L') jersey[i] =3;
}
forall(i,0,A){
cin >> S >> jer;
int si = -1;
if (S[0] == 'S') si = 1;
else if (S[0] == 'M') si = 2;
else if (S[0] == 'L') si = 3;
auto get = T.find(jer);
if (get != T.end()){
T[jer] = MIN(T[jer], si);
}
else {
T[jer] = si;
}
}
int ans = 0;
for(auto ii: T){
int k = ii.first;
int i = ii.second;
if (i > J) continue;
if (jersey[k-1]>=i)
ans++;
}
cout << ans;
}
```