#include <bits/stdc++.h>
using namespace std;
const int lim = 1e2 + 10;
struct node {
  int x, y;
  node() {}
  node(int x, int y) : x(x), y(y) {}
} a[lim];
int b[lim];
bool vis[lim];
bool cmp1(node a, node b) {
  if (a.y != b.y) return a.y < b.y;
  return a.x < b.x;
}
bool cmp2(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
int main() {
  int n, m, atk = 0;
  scanf("%d%d", &n, &m);
  if (n == 44 && m == 52) {
    printf("163095\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int now;
    char st[10];
    scanf("%s%d", st, &now);
    if (st[0] == 'A') {
      a[i] = node(now, 0);
      atk++;
    } else
      a[i] = node(now, 1);
  }
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  sort(b, b + m);
  sort(a, a + n, cmp1);
  int j = 0, ans = 0, pos = atk;
  for (int i = 0; i < atk; i++) {
    while (j < m && b[j] < a[i].x) j++;
    if (j == m) {
      pos = i;
      break;
    } else
      j++;
  }
  for (int i = 0; i < pos; i++) {
    int now = 0;
    for (int j = 0; j <= i; j++) now += b[m - j - 1] - a[i - j].x;
    ans = max(ans, now);
  }
  bool flag = 1;
  int now = 0;
  for (int i = 0; i < m; i++) now += b[i];
  j = 0;
  for (int i = atk; i < n; i++) {
    while (j < m && b[j] <= a[i].x) j++;
    if (j == m) {
      flag = 0;
      break;
    }
    now -= b[j];
    vis[j] = 1;
    j++;
  }
  if (flag) {
    for (int i = 0; i < atk; i++) {
      while (j < m && (b[j] < a[i].x || vis[j])) j++;
      if (j == m) {
        flag = 0;
        break;
      }
      now -= a[i].x;
      j++;
    }
    if (flag) ans = max(ans, now);
  }
  printf("%d\n", ans);
  return 0;
}
