#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int atk[N], atk2[N], def2[N];
bool mark[N];
int main() {
  int n, len;
  while (scanf("%d%d", &n, &len) != EOF) {
    int lena = 0, lend = 0, i, j;
    for (i = 0; i < n; i++) {
      char s[5];
      int v;
      scanf(" %s%d", s, &v);
      if (s[0] == 'A')
        atk2[lena++] = v;
      else
        def2[lend++] = v;
    }
    for (int i = 0; i < len; i++) scanf("%d", &atk[i]);
    sort(atk, atk + len);
    sort(atk2, atk2 + lena);
    sort(def2, def2 + lend);
    memset(mark, false, sizeof(mark));
    int ans1 = 0, ans2 = 0;
    for (i = 0, j = 0; i < lend && j < len; i++) {
      while (j < len && (mark[j] || atk[j] <= def2[i])) j++;
      if (j == len) break;
      mark[j] = true;
    }
    if (j < len) {
      for (i = 0, j = 0; i < lena && j < len; i++) {
        while (j < len && (mark[j] || atk[j] < atk2[i])) j++;
        if (j == len) break;
        mark[j] = true;
        ans1 += atk[j] - atk2[i];
      }
      if (j < len) {
        for (i = 0; i < len; i++)
          if (!mark[i]) ans1 += atk[i];
      } else
        ans1 = 0;
    }
    for (i = len - 1, j = 0; i >= 0 && j < lena && atk[i] >= atk2[j];
         i--, j++) {
      ans2 += atk[i] - atk2[j];
    }
    printf("%d\n", max(ans1, ans2));
  }
  return 0;
}
