#include <bits/stdc++.h>
using namespace std;
int greedy1(vector<int> atk, vector<int> myAtk) {
  vector<int>::iterator it1 = atk.begin();
  vector<int>::reverse_iterator it2 = myAtk.rbegin();
  int res = 0;
  while (1) {
    if (it1 == atk.end() || it2 == myAtk.rend() || *it1 >= *it2) break;
    res += *it2 - *it1;
    it1++;
    it2++;
  }
  return res;
}
int greedy2(vector<int> atk, vector<int> def, vector<int> myAtk) {
  int sumMyAtk = accumulate(myAtk.begin(), myAtk.end(), 0);
  bool vis[101] = {0};
  for (int i = 0; i < (int)def.size(); ++i) {
    bool flag = false;
    for (int j = 0; j < myAtk.size(); ++j) {
      if (vis[j] == 0 && def[i] < myAtk[j]) {
        vis[j] = 1;
        sumMyAtk -= myAtk[j];
        flag = 1;
        break;
      }
    }
    if (flag == false) return 0;
  }
  for (int i = 0; i < (int)atk.size(); ++i) {
    bool flag = false;
    for (int j = 0; j < myAtk.size(); ++j) {
      if (!vis[j] && atk[i] <= myAtk[j]) {
        vis[j] = 1;
        flag = 1;
        break;
      }
    }
    if (flag == false) return 0;
  }
  return sumMyAtk - accumulate(atk.begin(), atk.end(), 0);
}
int main() {
  int n, m, t;
  string s;
  vector<int> atk, def, myAtk;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s >> t;
    if (s[0] == 'A')
      atk.push_back(t);
    else
      def.push_back(t);
  }
  for (int i = 0; i < m; ++i) {
    cin >> t;
    myAtk.push_back(t);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(myAtk.begin(), myAtk.end());
  cout << max(greedy1(atk, myAtk), greedy2(atk, def, myAtk)) << endl;
  return 0;
}
