#include <bits/stdc++.h>
using namespace std;
int n, m;
int head[205], ecnt, st, ed, total;
int nodecnt[205], level[205];
int Ciel[205], Duel[205];
bool isATK[205];
typedef struct node {
  int u, v, flow, cost;
  int next;
  void in(int us, int vs, int flows, int costs, int nexts) {
    u = us, v = vs, flow = flows, cost = costs, next = nexts;
  }
} Edge;
Edge edges[205 * 205];
void init() {
  memset(head, -1, sizeof(head));
  ecnt = 0;
}
void addedge(int u, int v, int flow, int cost) {
  edges[ecnt].in(u, v, flow, cost, head[u]);
  head[u] = ecnt++;
}
void addedges(int u, int v, int flow, int cost) {
  addedge(u, v, flow, cost);
  addedge(v, u, 0, -cost);
}
bool vis[205];
int preEdge[205], dist[205];
bool spfa() {
  memset(vis, false, sizeof(vis));
  memset(preEdge, -1, sizeof(preEdge));
  for (int i = st; i <= ed; i++) dist[i] = 1000000000;
  vis[st] = true;
  dist[st] = 0;
  queue<int> qb;
  qb.push(st);
  while (!qb.empty()) {
    int u = qb.front();
    qb.pop();
    vis[u] = false;
    for (int i = head[u]; i != -1; i = edges[i].next) {
      int v = edges[i].v;
      if (edges[i].flow && dist[v] > dist[u] + edges[i].cost) {
        dist[v] = dist[u] + edges[i].cost;
        preEdge[v] = i;
        if (!vis[v]) {
          qb.push(v);
          vis[v] = true;
        }
      }
    }
  }
  if (dist[ed] == 1000000000) return false;
  return true;
}
bool allkill;
int MCMF(bool needfull) {
  int minflow;
  int maxflow = 0;
  int mincost = 1000000000;
  int tmpmin = 0;
  while (spfa()) {
    minflow = 1000000000;
    for (int i = preEdge[ed]; i != -1; i = preEdge[edges[i].u]) {
      minflow = min(minflow, edges[i].flow);
    }
    maxflow += minflow;
    for (int i = preEdge[ed]; i != -1; i = preEdge[edges[i].u]) {
      edges[i].flow -= minflow;
      edges[i ^ 1].flow += minflow;
    }
    tmpmin += dist[ed];
    if (!needfull)
      mincost = min(mincost, tmpmin);
    else
      mincost = tmpmin;
  }
  if (maxflow == m) allkill = true;
  return -mincost;
}
void buildmap() {
  init();
  for (int i = 1; i <= n; i++) {
    addedges(st, i, 1, 0);
  }
  for (int i = n + 1; i <= n + m; i++) {
    addedges(i, ed, 1, 0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (isATK[j] && Ciel[i] >= Duel[j]) {
        addedges(i, j + n, 1, Duel[j] - Ciel[i]);
      }
      if (!isATK[j] && Ciel[i] > Duel[j]) {
        addedges(i, j + n, 1, 0);
      }
    }
  }
}
int solve() {
  st = 0;
  ed = n + m + 1;
  total = ed + 1;
  buildmap();
  allkill = false;
  int first_mincost;
  first_mincost = MCMF(false);
  if (!allkill || n <= m) {
    if (first_mincost != -1000000000) return first_mincost;
    return 0;
  }
  ed = n + n + 1;
  total = ed + 1;
  buildmap();
  for (int j = m + 1; j <= n; j++) {
    int v = n + j;
    for (int i = 1; i <= n; i++) {
      addedges(i, v, 1, -Ciel[i]);
    }
  }
  for (int i = m + 1; i <= n; i++) {
    int v = n + i;
    addedges(v, ed, 1, 0);
  }
  int sec_mincost = MCMF(true);
  int ans = max(first_mincost, sec_mincost);
  if (ans == -1000000000) ans = 0;
  return ans;
}
int main() {
  string oper;
  int val;
  while (~scanf("%d%d", &m, &n)) {
    memset(isATK, false, sizeof(isATK));
    for (int i = 1; i <= m; i++) {
      cin >> oper >> val;
      if (oper == "ATK") {
        isATK[i] = true;
      }
      Duel[i] = val;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &val);
      Ciel[i] = val;
    }
    int ans = solve();
    printf("%d\n", ans);
  }
  return 0;
}
