#include <bits/stdc++.h>
using namespace std;
int n, m, def = 0, atk = 0;
int WarDef[102], WarAtk[102];
int Moje[102], Moje2[102];
int bez_def() {
  int odp = 0;
  int it = 0;
  while (WarAtk[it] < Moje[m - it - 1] && it != atk && m - it - 1 >= 0) {
    odp = odp + Moje[m - it - 1] - WarAtk[it];
    it++;
  }
  return odp;
}
int bierz_co_sie_da() {
  int odp = 0;
  int ile = atk;
  for (int i = (0); i < (ile); i++)
    for (int j = m - 1; j >= 0; j--)
      if (Moje2[j] >= WarAtk[i]) {
        odp = odp + (Moje2[j] - WarAtk[i]);
        Moje2[j] = -1;
        atk--;
        break;
      }
  if (atk == 0)
    for (int i = (0); i < (m); i++) odp = odp + max(0, Moje2[i]);
  return odp;
}
int zniszcz_atak() {
  int odp = 0;
  int ile = atk;
  for (int i = (0); i < (ile); i++)
    for (int j = (0); j < (m); j++)
      if (Moje[j] >= WarAtk[i]) {
        odp = odp + (Moje[j] - WarAtk[i]);
        Moje[j] = -1;
        atk--;
        break;
      }
  if (atk == 0)
    for (int i = (0); i < (m); i++) odp = odp + max(0, Moje[i]);
  return odp;
}
int z_def() {
  int odp = 0;
  int ile = def;
  for (int i = (0); i < (ile); i++) {
    for (int j = (0); j < (m); j++)
      if (Moje[j] > WarDef[i]) {
        Moje[j] = -1;
        def--;
        break;
      }
  }
  if (def == 0) {
    for (int i = (0); i < (m); i++) Moje2[i] = Moje[i];
    int aa = atk;
    int b = bierz_co_sie_da();
    atk = aa;
    int a = zniszcz_atak();
    odp += max(a, b);
  }
  return odp;
}
void dane() {
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    string s;
    int w;
    cin >> s >> w;
    if (s == "DEF") {
      WarDef[def] = w;
      def++;
    } else {
      WarAtk[atk] = w;
      atk++;
    }
  }
  for (int i = (0); i < (m); i++) scanf("%d", &Moje[i]);
  sort(Moje, Moje + m);
  sort(WarAtk, WarAtk + atk);
  int a = bez_def();
  int b = z_def();
  cout << max(a, b) << "\n";
}
int main() {
  dane();
  return 0;
}
