#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const long double pi = acos(-1.0);
int main() {
  int n, m, x;
  char cmd[100];
  vector<int> atk, def;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s%d", cmd, &x);
    if (strcmp(cmd, "ATK") == 0)
      atk.push_back(x);
    else
      def.push_back(x);
  }
  vector<int> a(m, 0);
  for (int i = 0; i < m; ++i) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  int profit = 0, cur_profit = 0;
  bool good = true;
  for (int i = 1; i <= min(((int)(atk).size()), ((int)(a).size())); ++i) {
    vector<int> J, F;
    for (int j = 0; j < i; ++j) J.push_back(atk[j]);
    for (int j = ((int)(a).size()) - i; j < ((int)(a).size()); ++j)
      F.push_back(a[j]);
    good = true, cur_profit = 0;
    for (int j = 0; j < i; ++j) {
      good &= (J[j] <= F[j]);
      cur_profit += F[j] - J[j];
    }
    profit = max(profit, cur_profit);
  }
  good = true, cur_profit = 0;
  for (int i = 0, j = 0; i < ((int)(def).size()); ++i) {
    while ((j < ((int)(a).size())) && (a[j] <= def[i])) ++j;
    if (j == ((int)(a).size())) {
      good = false;
      break;
    }
    a[j++] = -1;
  }
  sort(a.begin(), a.end());
  for (int i = 0, j = 0; i < ((int)(atk).size()); ++i) {
    while ((j < ((int)(a).size())) && (a[j] < atk[i])) ++j;
    if (j == ((int)(a).size())) {
      good = false;
      break;
    }
    cur_profit += a[j] - atk[i];
    a[j++] = -1;
  }
  sort(a.begin(), a.end());
  for (int j = 0; j < ((int)(a).size()); ++j)
    if (a[j] >= 0) cur_profit += a[j];
  if (good) profit = max(profit, cur_profit);
  printf("%d\n", profit);
  return 0;
}
