#include <bits/stdc++.h>
using namespace std;
multiset<int> mc;
multiset<int>::iterator it;
const int maxn = 210;
int a[maxn], b[maxn], c[maxn];
int cnta, cntb, cntc, n, m, ans, v, h;
char s[59];
void close() { exit(0); }
void work() {
  int maxatt = 0;
  for (int i = 1; i <= cntb; i++) {
    it = mc.upper_bound(b[i]);
    if (it == mc.end()) return;
    mc.erase(it);
  }
  for (int i = 1; i <= cnta; i++) {
    it = mc.lower_bound(a[i]);
    if (it == mc.end()) return;
    maxatt += *it - a[i];
    mc.erase(it);
  }
  for (it = mc.begin(); it != mc.end(); it++) maxatt += *it;
  ans = max(ans, maxatt);
}
void init() {
  scanf("%d %d", &n, &m);
  cnta = cntb = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s %d", s, &v);
    if (s[0] == 'A') {
      cnta++;
      a[cnta] = v;
    } else {
      cntb++;
      b[cntb] = v;
    }
  }
  sort(a + 1, a + cnta + 1);
  sort(b + 1, b + cntb + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &c[i]);
    mc.insert(c[i]);
  }
  sort(c + 1, c + m + 1);
  h = 1;
  ans = 0;
  for (int i = m; i >= 1; i--) {
    if (a[h] > c[i]) break;
    ans += c[i] - a[h];
    h++;
    if (h > cnta) break;
  }
  work();
  printf("%d\n", ans);
}
int main() {
  init();
  close();
  return 0;
}
