#include <bits/stdtr1c++.h>

using namespace std;

typedef long long ll;

ll J;
ll A;


int main ()
{
	cin >> J;
	cin >> A;

	vector<char> jerseys (J+1);
	vector<bool> satisfied (J+1);


	for (int i = 1; i <= J; i++)
	{
		string size;
		cin >> size;
		if (size == "S") jerseys [i] = 1;
		else if (size == "M") jerseys [i] = 2;
		else jerseys [i] = 3;
	}	

	int num_satisfied = 0;

	for (int i = 1; i <= A; i++)
	{
		string x;
		int number;
		int size;
		cin >> x;
		cin >> number;

		if (x == "S") size = 1;
		else if (x == "M") size = 2;
		else size = 3;

		if ((jerseys [number] >= size) && (satisfied [number] == 0))
		{
			num_satisfied++;
			satisfied [number] = true;
		}
	}

	cout << num_satisfied;

}