#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> Jdef, Jatk, Catk;
  Jdef.reserve(n);
  Jatk.reserve(n);
  Catk.reserve(m);
  for (long long(i) = 0; (i) < (n); (i)++) {
    string s;
    int st;
    cin >> s >> st;
    ;
    if (s == "ATK")
      Jatk.push_back(st);
    else if (s == "DEF")
      Jdef.push_back(st);
    else
      assert(0);
  }
  for (long long(i) = 0; (i) < (m); (i)++) {
    int st;
    cin >> st;
    Catk.push_back(st);
  }
  sort(Jdef.begin(), Jdef.end());
  sort(Jatk.begin(), Jatk.end());
  sort(Catk.begin(), Catk.end());
  long long atk_only = 0;
  {
    for (int Jend = Jatk.size(); Jend > 0; Jend--) {
      long long tmp = 0;
      int Ci = Catk.size() - 1;
      for (int Ji = Jend - 1; Ji >= 0; Ji--) {
        if (Ci < 0 || Catk[Ci] < Jatk[Ji]) break;
        tmp += Catk[Ci] - Jatk[Ji];
        Ci--;
      }
      atk_only = max(atk_only, tmp);
    }
  }
  long long def_and = 0;
  {
    for (long long(i) = 0; (i) < (Jdef.size()); (i)++) {
      auto ptr = upper_bound(begin(Catk), end(Catk), Jdef[i]);
      if (ptr == Catk.end()) {
        goto DEFANDEND;
      }
      Catk.erase(ptr);
    }
    int Ji = Jatk.size() - 1;
    for (int Ci = Catk.size() - 1; Ci >= 0; Ci--) {
      if (Ji >= 0) {
        if (Catk[Ci] < Jatk[Ji]) break;
        def_and += Catk[Ci] - Jatk[Ji];
        Ji--;
      } else {
        def_and += Catk[Ci];
      }
    }
  }
DEFANDEND:
  cout << max(atk_only, def_and) << endl;
  return 0;
}
