#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, la, ld;
char ch[110];
const int INF = 10000000;
int atk[1100], def[1100], pos, head[41000], a[1100], last[41000], pre[41000],
    flow[41000], cost[41000], vis[41000];
struct node {
  int next, to;
  int flow, cost;
} fbk[41000];
void add(int u, int v, int f, int c) {
  fbk[++pos].next = head[u];
  fbk[pos].to = v;
  fbk[pos].flow = f;
  fbk[pos].cost = c;
  head[u] = pos;
  fbk[++pos].next = head[v];
  fbk[pos].to = u;
  fbk[pos].flow = 0;
  fbk[pos].cost = -c;
  head[v] = pos;
}
int spfa() {
  int i, j, k;
  memset(vis, 0, sizeof(vis));
  for (i = 0; i <= t; i++) flow[i] = cost[i] = 10 * INF;
  queue<int> woc;
  cost[s] = 0, pre[t] = -1, vis[s] = 1;
  woc.push(s);
  while (!woc.empty()) {
    int u = woc.front();
    woc.pop();
    vis[u] = 0;
    for (i = head[u]; i != -1; i = fbk[i].next) {
      int v = fbk[i].to;
      if (fbk[i].flow > 0 && cost[v] > cost[u] + fbk[i].cost) {
        cost[v] = cost[u] + fbk[i].cost;
        flow[v] = min(flow[u], fbk[i].flow);
        pre[v] = u;
        last[v] = i;
        if (!vis[v]) {
          woc.push(v);
          vis[v] = 1;
        }
      }
    }
  }
  return cost[t];
}
int mcmf() {
  int well = 0, temp = 0;
  int i, j;
  for (i = 1; i <= n; i++) {
    int d = spfa();
    if (d >= INF) return -well;
    temp += d;
    well = min(well, temp);
    int now = t;
    while (now != s) {
      fbk[last[now]].flow -= 1;
      fbk[last[now] ^ 1].flow += 1;
      now = pre[now];
    }
  }
  for (i = n + 1; i <= m; i++) {
    int d = spfa();
    if (d == INF * 10) return -well;
    temp += d - 2 * INF;
    well = min(well, temp);
    int now = t;
    while (now != s) {
      fbk[last[now]].flow -= 1;
      fbk[last[now] ^ 1].flow += 1;
      now = pre[now];
    }
  }
  return -well;
}
int main() {
  pos = -1;
  cin >> n >> m;
  int i, j, k;
  s = 0, t = n + m + 1;
  memset(head, -1, sizeof(head));
  for (i = 1; i <= n; i++) {
    scanf("%s%d", ch, &k);
    if (ch[0] == 'A')
      atk[++la] = k;
    else
      def[++ld] = k;
  }
  for (i = 1; i <= n; i++) add(i + m, t, 1, 0);
  for (i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    add(s, i, 1, 0);
    add(i, t, 1, 2 * INF - a[i]);
    for (j = 1; j <= la; j++)
      if (a[i] >= atk[j]) add(i, j + m, 1, -a[i] + atk[j]);
    for (j = 1; j <= ld; j++)
      if (a[i] > def[j]) add(i, j + m + la, 1, 0);
  }
  int ans = mcmf();
  cout << ans << endl;
  return 0;
}
