#include <bits/stdc++.h>
using namespace std;
struct Node {
  int u, v, next;
  int cap, cost;
} edge[200010];
int head[440], a[440], val[111];
char str[111][10];
void add_edge(int u, int v, int cap, int cost, int &num) {
  edge[num].cap = cap;
  edge[num].u = u;
  edge[num].v = v;
  edge[num].cost = cost;
  edge[num].next = head[u];
  head[u] = num++;
  edge[num].cap = 0;
  edge[num].u = v;
  edge[num].v = u;
  edge[num].cost = -cost;
  edge[num].next = head[v];
  head[v] = num++;
}
int get_map(int n, int m, int flag) {
  int num = 0, s = 0, t = m + n + 1;
  for (int i = 0; i <= n + m + 3; i++) head[i] = -1;
  for (int i = 1; i <= m; i++) {
    add_edge(s, i, 1, 0, num);
    for (int j = 1; j <= n; j++) {
      if (str[j][0] == 'A' && val[j] <= a[i])
        add_edge(i, m + j, 1, a[i] - val[j], num);
      if (str[j][0] == 'D' && a[i] > val[j] && flag == 1)
        add_edge(i, m + j, 1, 0, num);
    }
  }
  for (int i = 1; i <= n; i++) add_edge(i + m, t, 1, 0, num);
  return num;
}
int que[200010], pre[440], dis[440];
char mark[440];
bool spfa(int s, int t, int n) {
  int front = 0, rear = 0;
  for (int i = 0; i <= n; i++) mark[i] = 0, dis[i] = -0x7fffffff, pre[i] = -1;
  que[rear++] = s;
  dis[s] = 0;
  mark[s] = 1;
  while (front != rear) {
    int u = que[front++];
    front = front == 200010 ? 0 : front;
    mark[u] = 0;
    for (int p = head[u]; p != -1; p = edge[p].next) {
      int v = edge[p].v;
      if (edge[p].cap > 0 && dis[v] < edge[p].cost + dis[u]) {
        dis[v] = dis[u] + edge[p].cost;
        pre[v] = p;
        if (!mark[v]) {
          mark[v] = 1;
          que[rear++] = v;
          rear = rear == 200010 ? 0 : rear;
        }
      }
    }
  }
  if (dis[t] == -0x7fffffff) return false;
  return true;
}
void mincost(int s, int t, int n, int &flow, int &cost, int flag) {
  while (spfa(s, t, n)) {
    int min_cap = 0x7fffffff;
    for (int u = t; u != s; u = edge[pre[u]].u)
      if (min_cap > edge[pre[u]].cap) min_cap = edge[pre[u]].cap;
    flow += min_cap;
    if (dis[t] < 0 && flag == 1) return;
    for (int u = t; u != s; u = edge[pre[u]].u) {
      edge[pre[u]].cap -= min_cap;
      edge[pre[u] ^ 1].cap += min_cap;
      cost += edge[pre[u]].cost * min_cap;
    }
  }
}
int main() {
  int m, n;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s%d", str[i], &val[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
  int s = 0, t = m + n + 1;
  get_map(n, m, 0);
  int flow = 0, cost = 0;
  mincost(s, t, n + m + 1, flow, cost, 1);
  if (m >= n) {
    int num = get_map(n, m, 1);
    add_edge(t + 1, t, m - n, 0, num);
    for (int i = 1; i <= m; i++) add_edge(i, t + 1, 1, a[i], num);
    int f = 0, c = 0;
    mincost(s, t, m + n + 2, f, c, 0);
    if (f == m && c > cost) cost = c;
  }
  printf("%d\n", cost);
  return 0;
}
