#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int ack[maxn], def[maxn];
int ciel[maxn];
int n, m;
int num_ack;
int num_def;
int vis[maxn];
int vis1[maxn];
int jiro[maxn];
int slv1() {
  int ans = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = m - 1; i >= 0; i--) {
    for (int j = 0; j < num_ack; j++) {
      if (ciel[i] <= ack[j]) break;
      if (vis[j]) continue;
      vis[j] = 1;
      ans += ciel[i] - ack[j];
      break;
    }
  }
  return ans;
}
int slv2() {
  int ans = 0;
  if (ciel[m - 1] < ack[num_ack - 1]) return 0;
  if (ciel[m - 1] <= def[num_def - 1]) return 0;
  if (m < n) return 0;
  int tot = n;
  memset(vis, 0, sizeof(vis));
  int t_a, t_b;
  int i, j;
  for (i = 0; i < num_def; i++) {
    for (j = 0; j < m; j++) {
      if (vis[j]) continue;
      if (ciel[j] > def[i]) {
        tot--;
        vis[j] = 1;
        break;
      }
    }
    if (j == m) return 0;
  }
  for (i = 0; i < num_ack; i++) {
    for (j = 0; j < m; j++) {
      if (vis[j]) continue;
      if (ciel[j] >= ack[i]) {
        tot--;
        vis[j] = 1;
        ans += ciel[j] - ack[i];
        break;
      }
    }
    if (j == m) return 0;
  }
  if (tot > 0) return 0;
  for (int i = 0; i < m; i++)
    if (vis[i] == 0) ans += ciel[i];
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  char str[5];
  num_ack = 0;
  num_def = 0;
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s %d", str, &tmp);
    if (str[0] == 'A') ack[num_ack++] = tmp;
    if (str[0] == 'D') def[num_def++] = tmp;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &ciel[i]);
  }
  sort(ciel, ciel + m);
  sort(ack, ack + num_ack);
  sort(def, def + num_def);
  printf("%d\n", max(slv1(), slv2()));
}
