#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int N, M, a[400], b[400], V, src, tar, mx, S, T;
int adj[400][400], cap[400][400], cost[400][400];
int dis[400], q[400 * 400], qf, qb, pre[400], C, deg[400];
char s[400][10];
void init() {
  memset(pre, -1, sizeof(pre));
  memset(deg, 0, sizeof(deg));
}
void add_edge(int u, int v, int w, int c) {
  adj[u][deg[u]++] = v;
  adj[v][deg[v]++] = u;
  cap[u][v] = w;
  cap[v][u] = 0;
  cost[u][v] = c;
  cost[v][u] = -c;
}
int Mincost_Maxflow() {
  int ans = 0, bot;
  C = 0;
  while (1) {
    memset(dis, 0x3f, sizeof(dis));
    qf = qb = 0;
    dis[src] = 0;
    q[qb++] = src;
    while (qf < qb) {
      int u = q[qf++];
      for (int i = 0; i < deg[u]; i++) {
        int v = adj[u][i];
        if (cap[u][v] == 0) continue;
        if (dis[v] > dis[u] + cost[u][v]) {
          dis[v] = dis[u] + cost[u][v];
          q[qb++] = v;
          pre[v] = u;
        }
      }
    }
    if (dis[tar] >= 0x3f3f3f3f) return ans;
    bot = 0x3f3f3f3f;
    for (int u = tar; u != src; u = pre[u]) bot = min(bot, cap[pre[u]][u]);
    ans += bot;
    for (int u = tar; u != src; u = pre[u]) {
      cap[pre[u]][u] -= bot;
      cap[u][pre[u]] += bot;
    }
    C += dis[tar] * bot;
  }
  return ans;
}
int main() {
  gn(N);
  gn(M);
  for (int i = 1; i <= N; i++) {
    scanf("%s", s[i]);
    gn(a[i]);
  }
  for (int i = 1; i <= M; i++) gn(b[i]);
  src = 0;
  tar = M + N + 1;
  S = M + N + 2;
  T = M + N + 3;
  for (int k = 1; k <= M; k++) {
    init();
    add_edge(src, S, k, 0);
    for (int i = 1; i <= M; i++) {
      add_edge(S, i, 1, 0);
      add_edge(i, T, 1, -b[i]);
      for (int j = 1; j <= N; j++) {
        if (b[i] >= a[j] && s[j][0] == 'A')
          add_edge(i, j + M, 1, a[j] - b[i]);
        else if (b[i] > a[j] && s[j][0] == 'D')
          add_edge(i, j + M, 1, 0);
      }
    }
    for (int i = 1; i <= N; i++) add_edge(M + i, tar, 1, 0);
    add_edge(T, tar, M, 100000);
    Mincost_Maxflow();
    if (cap[tar][T] > max(0, k - N)) continue;
    mx = max(mx, -C + cap[tar][T] * 100000);
  }
  printf("%d\n", mx);
  return 0;
}
