#include <bits/stdc++.h>
using namespace std;
int n, m;
int nd, na;
int nm;
int atq[124], def[124], meu[124];
int foi[124];
int killAll() {
  memset(foi, 0, sizeof(foi));
  for (int i = 0; i < nd; i++) {
    int j = 0;
    while (j < nm && (meu[j] <= def[i] || foi[j] == 1)) j++;
    if (j == nm)
      return 0;
    else
      foi[j] = 1;
  }
  int ans = 0;
  for (int i = 0; i < na; i++) {
    int j = 0;
    while (j < nm && (meu[j] < atq[i] || foi[j])) j++;
    if (j == nm) return 0;
    if (meu[j] >= atq[i] && !foi[j]) {
      ans += meu[j] - atq[i];
      foi[j] = 1;
    }
  }
  for (int j = 0; j < nm; j++)
    if (!foi[j]) ans += meu[j];
  return ans;
}
int killAtq() {
  int me = min(nm, na);
  int ans = 0;
  for (int k = 1; k <= me; k++) {
    int j = nm - k;
    int aux = 0;
    for (int i = 0; i < k; i++, j++) {
      if (meu[j] >= atq[i]) {
        aux += meu[j] - atq[i];
      }
    }
    ans = max(ans, aux);
  }
  return ans;
}
int main() {
  char s[124];
  scanf(" %d %d", &n, &m);
  nd = na = nm = 0;
  int p;
  for (int i = 0; i < n; i++) {
    scanf(" %s %d", s, &p);
    if (!strcmp("ATK", s)) atq[na++] = p;
    if (!strcmp("DEF", s)) def[nd++] = p;
  }
  for (int i = 0; i < m; i++) {
    scanf(" %d", &p);
    meu[nm++] = p;
  }
  sort(atq, atq + na);
  sort(def, def + nd);
  sort(meu, meu + nm);
  printf("%d\n", max(killAll(), killAtq()));
  return 0;
}
