#include <bits/stdc++.h>
int n, m, atk[105], def[105], w[105], aCnt, dCnt;
int atkALL() {
  bool u[105] = {0};
  int sum = 0, kCnt = 0;
  for (int i = 0, j = 0; i < dCnt; i++) {
    for (; j < m; j++)
      if (w[j] > def[i]) {
        u[j++] = true;
        kCnt++;
        break;
      }
  }
  if (kCnt != dCnt) return -1;
  for (int i = m - 1, j = aCnt - 1; i >= 0 && j >= 0; i--) {
    if (u[i]) continue;
    if (w[i] < atk[j]) return -1;
    sum += w[i] - atk[j];
    j--;
    u[i] = true;
  }
  for (int i = 0; i < m; i++)
    if (!u[i]) sum += w[i];
  return sum;
}
int chk(int k) {
  int ret = 0;
  for (int i = 0, j = m - 1; i < k; i++) {
    if (w[j] < atk[i]) return -1;
    ret += w[j--] - atk[i];
  }
  return ret;
}
int notALL() {
  int retVal = 0;
  for (int i = 1; i <= aCnt; i++) {
    int v = chk(i);
    if (v > retVal) retVal = v;
  }
  return retVal;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    char buf[5];
    int val;
    scanf("%s%d", buf, &val);
    if (buf[0] == 'A')
      atk[aCnt++] = val;
    else
      def[dCnt++] = val;
  }
  for (int i = 0; i < m; i++) scanf("%d", &w[i]);
  std::sort(atk, atk + aCnt);
  std::sort(def, def + dCnt);
  std::sort(w, w + m);
  printf("%d\n", std::max(atkALL(), notALL()));
}
