#include <bits/stdc++.h>
using namespace std;
const int MX = 109;
int n, m;
int ciel[MX];
int atk[MX], def[MX];
int cnt_atk, cnt_def;
int solve_all(void) {
  int result = 0, iter_atk = 0, iter_def = 0;
  for (int i = 0; i < m; i++) {
    if (iter_def < cnt_def && ciel[i] > def[iter_def])
      iter_def++;
    else if (iter_atk < cnt_atk && ciel[i] >= atk[iter_atk]) {
      result += ciel[i] - atk[iter_atk];
      iter_atk++;
    } else
      result += ciel[i];
  }
  if (iter_atk < cnt_atk || iter_def < cnt_def) return 0;
  return result;
}
int solve_only_atk(void) {
  int result = 0;
  for (int i = m - 1, j = 0; i >= 0 && j < cnt_atk && ciel[i] >= atk[j];
       i--, j++) {
    result += ciel[i] - atk[j];
  }
  return result;
}
int main() {
  cin >> n >> m;
  cnt_atk = 0, cnt_def = 0;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "ATK")
      cin >> atk[cnt_atk++];
    else
      cin >> def[cnt_def++];
  }
  for (int i = 0; i < m; i++) cin >> ciel[i];
  sort(ciel, ciel + m);
  sort(atk, atk + cnt_atk);
  sort(def, def + cnt_def);
  int result = 0;
  result = max(result, solve_all());
  result = max(result, solve_only_atk());
  cout << result;
  return 0;
}
