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

short size[1024000];
bool seen[1024000];

inline int sti(string s) {
    if (s == "S") return 1;
    if (s == "M") return 2;
    if (s == "L") return 3;
    return 0;
}

int main() {
    int j, a;
    cin >> j >> a;

    memset(seen, 0, sizeof(seen));

    for (int i = 1; i <= j; ++i) {
        string s;
        cin >> s;
        size[i] = sti(s);
    }

    int total = 0;

    for (int i = 0; i < a; ++i) {
        string s;
        int n;
        cin >> s >> n;

        int ss = sti(s);

        if (seen[n]) continue;

        if (size[n] >= ss) {
            seen[n] = true;
            ++total;
        }
    }

    cout << total << endl;
}