#include <bits/stdc++.h>
using namespace std;
const int MAXN = 111;
int N, M;
vector<int> atk;
vector<int> def;
vector<int> vec;
int main() {
  cin >> N >> M;
  string s;
  for (int a, i = 0; i < N; i++) {
    cin >> s >> a;
    if (s == "ATK")
      atk.push_back(a);
    else
      def.push_back(a);
  }
  for (int a, i = 0; i < M; i++) {
    scanf(" %d", &a);
    vec.push_back(a);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int res = 0;
  for (int i = 0; i < ((int)atk.size()) && i < ((int)vec.size()); i++) {
    if (atk[i] > vec[i]) break;
    res += vec[i] - atk[i];
  }
  reverse(vec.begin(), vec.end());
  vector<int> lf;
  int i = 0;
  int j = 0;
  for (; i < ((int)vec.size()) && j < ((int)def.size()); i++) {
    if (def[j] < vec[i])
      j++;
    else
      lf.push_back(vec[i]);
  }
  for (; i < ((int)vec.size()); i++) lf.push_back(vec[i]);
  if (j < ((int)def.size())) {
    printf("%d\n", res);
    return 0;
  }
  sort(lf.begin(), lf.end());
  reverse(lf.begin(), lf.end());
  sort(atk.begin(), atk.end());
  reverse(atk.begin(), atk.end());
  i = 0, j = 0;
  int tmp = 0;
  for (; i < ((int)lf.size()) && j < ((int)atk.size()); i++) {
    if (lf[i] >= atk[j]) {
      tmp += lf[i] - atk[j];
      j++;
    } else {
      printf("%d\n", res);
      return 0;
    }
  }
  for (; i < ((int)lf.size()); i++) tmp += lf[i];
  res = max(res, tmp);
  printf("%d\n", res);
  return 0;
}
