#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cap, rev, cost;
};
vector<edge> E[500];
void add_edge(int from, int to, int cap, int cost) {
  E[from].push_back((edge){to, cap, (int)E[to].size(), cost});
  E[to].push_back((edge){from, 0, (int)E[from].size() - 1, -cost});
}
int n, m, x1[101], y[101], start, endd, ans, result = 0;
char x2[101][10];
int way_p[300], way_n[300];
bool spfa() {
  bool used[300] = {0};
  double dist[300];
  for (int i = start; i <= endd; i++) dist[i] = 0x3f3f3f3f;
  queue<int> que;
  que.push(0);
  used[0] = true;
  dist[0] = 0;
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int i = 0; i < E[now].size(); i++) {
      edge &e = E[now][i];
      if (e.cap > 0 && dist[e.to] > e.cost + dist[now]) {
        dist[e.to] = e.cost + dist[now];
        way_p[e.to] = now;
        way_n[e.to] = i;
        if (used[e.to] == false) {
          que.push(e.to);
          used[e.to] = true;
        }
      }
    }
    used[now] = false;
  }
  if (dist[endd] >= 0x3f3f3f3f) return false;
  return true;
}
void work() {
  int now = endd, f = 0x3f3f3f3f;
  while (now != start) {
    edge &e = E[way_p[now]][way_n[now]];
    f = min(f, e.cap);
    now = way_p[now];
  }
  now = endd;
  while (now != 0) {
    edge &e = E[way_p[now]][way_n[now]];
    e.cap -= f;
    E[e.to][e.rev].cap += f;
    ans += (e.cost * f);
    now = way_p[now];
  }
  return;
}
void calc_back() {
  bool f = 0;
  for (int i = 0; i < E[endd].size(); i++) {
    if (m + 2 <= E[endd][i].to) {
      ans += E[endd][i].cost * E[endd][i].cap;
      if (!E[endd][i].cap) f = true;
    }
  }
  if (f) {
    for (int i = 0; i < E[endd].size(); i++)
      if (E[endd][i].to < m + 2) ans += E[endd][i].cost * E[endd][i].cap;
  }
  ans = -ans;
}
void build_e(int c) {
  for (int i = 0; i < 500; i++) E[i].clear();
  start = 0;
  endd = m + n + 2;
  add_edge(start, 1, c, 0);
  for (int i = 0; i < m; i++)
    add_edge(1, 2 + i, 1, 0), add_edge(2 + i, endd, 1, -y[i]);
  for (int i = 0; i < n; i++) add_edge(m + 2 + i, endd, 1, -10000);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      if (x2[j][0] == 'A') {
        if (y[i] >= x1[j]) add_edge(2 + i, m + 2 + j, 1, x1[j] - y[i]);
      } else {
        if (y[i] > x1[j]) add_edge(2 + i, m + 2 + j, 1, 0);
      }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s%d", x2[i], &x1[i]);
  for (int i = 0; i < m; i++) scanf("%d", &y[i]);
  for (int i = 0; i <= m; i++) {
    ans = 0;
    build_e(i);
    while (spfa()) {
      work();
    }
    calc_back();
    result = max(ans, result);
  }
  printf("%d\n", result);
  return 0;
}
