#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using std::bitset;
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
using std::bitset;
using namespace std;
struct node {
  int k, v;
  bool operator<(const node &I) const {
    return v < I.v || (v == I.v && k < I.k);
  }
} b[220];
int a[220];
int fa[220], fb[220];
int n, m;
int cau1() {
  int i, j, tem;
  int ans = 0;
  memset(fa, 0, sizeof(fa));
  ;
  memset(fb, 0, sizeof(fb));
  ;
  j = 1;
  for (i = 1; i <= n; i++)
    if (b[i].k == 1) {
      fa[i] = 1;
      while (j <= m && (a[j] <= b[i].v || fb[j] == 1)) j++;
      if (j > m) return 0;
      fb[j] = 1;
    }
  for (j = m; fb[j] && j > 0; j--)
    ;
  for (i = n; i > 0; i--)
    if (fa[i] == 0) {
      while (j > 0 && fb[j]) j--;
      if (j == 0 || a[j] < b[i].v) return 0;
      ans += a[j] - b[i].v;
      fb[j] = 1;
    }
  for (; j > 0; j--)
    if (fb[j] == 0) ans += a[j];
  return ans;
}
int cau2() {
  int i, j, tem, ans;
  ans = 0;
  j = m;
  for (i = 1; i <= n; i++)
    if (b[i].k == 0) {
      if (j == 0 || a[j] < b[i].v) return ans;
      ans += a[j] - b[i].v;
      j--;
    }
  return ans;
}
int main() {
  int i, j, tem;
  char st[220];
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%s%d", st, &b[i].v);
      if (st[0] == 'A')
        b[i].k = 0;
      else
        b[i].k = 1;
    }
    sort(b + 1, b + 1 + n);
    for (i = 1; i <= m; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + m);
    int ans = 0;
    ans = max(ans, cau1());
    ans = max(ans, cau2());
    printf("%d\n", ans);
  }
  return 0;
}
