#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 40010, INF = 10000000;
int n, m, cnt, fir[N], nxt[M], to[M], cap[M], val[M];
int vis[N], dis[N], path[N], q[N], front, back;
void addedge(int a, int b, int c, int v) {
  nxt[++cnt] = fir[a];
  to[fir[a] = cnt] = b;
  cap[cnt] = c;
  val[cnt] = v;
  nxt[++cnt] = fir[b];
  to[fir[b] = cnt] = a;
  cap[cnt] = 0;
  val[cnt] = -v;
}
int BFS(int S, int T) {
  for (int i = S + 1; i <= T; i++) dis[i] = 10 * INF;
  q[front = back = 1] = S;
  vis[S] = true;
  while (front <= back) {
    int x = q[front++];
    vis[x] = false;
    for (int i = fir[x]; i; i = nxt[i])
      if (cap[i] && dis[to[i]] > dis[x] + val[i]) {
        dis[to[i]] = dis[x] + val[i];
        if (!vis[to[i]]) q[++back] = to[i];
        vis[to[i]] = true;
        path[to[i]] = i;
      }
  }
  return dis[T];
}
void Aug(int S, int T) {
  int p = T;
  while (p != S) {
    cap[path[p]] -= 1;
    cap[path[p] ^ 1] += 1;
    p = to[path[p] ^ 1];
  }
}
int McMf(int S, int T) {
  int ret = 0, d, tmp = 0;
  for (int i = 1; i <= n; i++) {
    d = BFS(S, T);
    if (d >= INF) return -ret;
    tmp += d;
    ret = min(ret, tmp);
    Aug(S, T);
  }
  for (int i = n + 1; i <= m; i++) {
    d = BFS(S, T);
    if (d == 10 * INF) return -ret;
    tmp += d - 2 * INF;
    ret = min(ret, tmp);
    Aug(S, T);
  }
  return -ret;
}
int A[N], D[N], B[N], ca, cd, S, T, x;
void Init() {
  memset(dis, 0, sizeof(dis));
  memset(fir, 0, sizeof(fir));
  front = back = cnt = 1;
}
char op[5];
int main() {
  Init();
  scanf("%d%d", &n, &m);
  S = 0;
  T = n + m + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%s%d", op, &x);
    if (op[0] == 'A') A[++ca] = x;
    if (op[0] == 'D') D[++cd] = x;
  }
  for (int i = 1; i <= n; i++) addedge(i + m, T, 1, 0);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &B[i]);
    addedge(S, i, 1, 0);
    addedge(i, T, 1, 2 * INF - B[i]);
    for (int j = 1; j <= ca; j++)
      if (A[j] <= B[i]) addedge(i, m + j, 1, -B[i] + A[j]);
    for (int j = 1; j <= cd; j++)
      if (D[j] < B[i]) addedge(i, m + j + ca, 1, 0);
  }
  printf("%d\n", McMf(S, T));
  return 0;
}
