#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a, d;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int k;
    cin >> k;
    if (s == "ATK")
      a.push_back(k);
    else
      d.push_back(k);
  }
  vector<int> b(m);
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(b.rbegin(), b.rend());
  sort(a.begin(), a.end());
  int res = 0;
  for (int i = 0; i < min(a.size(), b.size()); i++) {
    if (b[i] > a[i]) res += b[i] - a[i];
  }
  {
    sort(d.begin(), d.end());
    sort(b.begin(), b.end());
    int i = 0, j = 0;
    for (; i < d.size() and j < b.size(); i++) {
      while (j < b.size() and b[j] <= d[i]) {
        j++;
      }
      if (j < b.size())
        b[j] = 0;
      else
        i--;
    }
    if (i == d.size()) {
      int r = 0;
      sort(b.rbegin(), b.rend());
      sort(a.rbegin(), a.rend());
      bool br = true;
      for (i = 0; i < min(a.size(), b.size()); i++) {
        if (b[i] >= a[i])
          r += b[i] - a[i];
        else
          br = false;
      }
      if (br)
        for (i = min(a.size(), b.size()); i < b.size(); i++) {
          r += b[i];
        }
      res = max(res, r);
    }
  }
  cout << res << endl;
}
