#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 2 * 1000 * 1000 * 1000;
const int MAXN = 2 * 1000 * 1000;
string s;
int n, m, st, posl, ans, posr, sum, pos, used[2000];
vector<int> def, atk, ciel;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s >> st;
    if (s == "DEF")
      def.push_back(st);
    else
      atk.push_back(st);
  }
  sort(def.begin(), def.end());
  sort(atk.begin(), atk.end());
  for (int i = 1; i <= m; i++) {
    cin >> st;
    ciel.push_back(st);
  }
  sort(ciel.begin(), ciel.end());
  for (int i = 0; i < ciel.size(); i++) {
    if (posl >= def.size()) break;
    if (ciel[i] > def[posl]) used[i] = 1, posl++;
  }
  if (posl >= def.size()) {
    for (int i = 0; i < ciel.size(); i++) {
      if (posr >= atk.size()) break;
      if (!used[i] && ciel[i] >= atk[posr])
        ans += ciel[i] - atk[posr], used[i] = 1, posr++;
    }
    if (posr >= atk.size())
      for (int i = 0; i < ciel.size(); i++)
        if (!used[i]) ans += ciel[i];
  }
  pos = (int)ciel.size() - 1;
  for (int i = 0; i < atk.size(); i++) {
    if (pos >= 0 && ciel[pos] >= atk[i]) sum += ciel[pos--] - atk[i];
  }
  cout << max(sum, ans);
  return 0;
}
