#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  vector<int> all, atk, def, have;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int s;
    string type;
    cin >> type >> s;
    all.push_back(s);
    if (type == "ATK")
      atk.push_back(s);
    else
      def.push_back(s);
  }
  have.assign(m, 0);
  for (int i = 0; i < m; i++) cin >> have[i];
  sort(have.begin(), have.end());
  sort(def.begin(), def.end());
  sort(atk.begin(), atk.end());
  if (m >= n) {
    vector<char> used(m, 0);
    bool can = 1;
    for (int i = (int)def.size() - 1; i >= 0; i--) {
      int dif = 10000000, v = -1;
      for (int j = 0; j < m; j++)
        if (!used[j] && have[j] > def[i] && have[j] - def[i] < dif)
          v = j, dif = have[j] - def[i];
      if (v == -1) {
        can = 0;
        break;
      }
      used[v] = 1;
    }
    int sum = 0;
    for (int i = (int)atk.size() - 1; i >= 0; i--) {
      int v = -1;
      for (int j = m - 1; j >= 0; j--)
        if (!used[j]) {
          v = j;
          break;
        }
      if (v == -1 || atk[i] > have[v]) {
        can = 0;
        break;
      }
      used[v] = 1;
      sum += have[v] - atk[i];
    }
    for (int i = 0; i < m; i++)
      if (!used[i]) sum += have[i];
    if (can) ans = sum;
  }
  reverse(have.begin(), have.end());
  int sum = 0;
  for (int i = 0; i < min(m, (int)atk.size()); i++)
    if (have[i] >= atk[i]) sum += have[i] - atk[i];
  ans = max(sum, ans);
  cout << ans;
  return 0;
}
