#include <bits/stdc++.h>
using namespace std;
int n, m, C[110], JA[110], JD[110], CC[110], cnt = 0;
char s[10];
int text(int k, int m, int* C) {
  int ans = 0;
  for (int i = m - 1; i >= k; i--) {
    if (C[i] >= JA[i - k])
      ans += (C[i] - JA[i - k]);
    else
      return -1;
  }
  return ans;
}
int get_cc(int x) {
  int cn = 0, co = 0;
  for (int i = 0; i < m; i++) {
    if (cn < x && C[i] > JD[cn])
      cn++;
    else
      CC[co++] = C[i];
  }
  if (cn < x)
    return -1;
  else
    return co;
}
int main() {
  scanf("%d %d", &n, &m);
  int cot = 0, x;
  for (int i = 0; i < n; i++) {
    scanf("%s%d", s, &x);
    if (s[0] == 'A')
      JA[cnt++] = x;
    else
      JD[cot++] = x;
  }
  for (int i = 0; i < m; i++) scanf("%d", &C[i]);
  sort(JA, JA + cnt);
  sort(JD, JD + cot);
  sort(C, C + m);
  int Max = 0, p = 0, val;
  for (int i = m - 1; m - 1 - i < cnt; i--) {
    val = text(i, m, C);
    if (Max <= val) Max = val, p = m - i;
  }
  int ccn = get_cc(cot);
  if (ccn == -1)
    printf("%d\n", Max);
  else {
    int Max1 = 0, p1 = 0, val1;
    for (int i = ccn - 1; ccn - 1 - i < cnt; i--) {
      val1 = text(i, ccn, CC);
      if (Max1 <= val1) Max1 = val1, p1 = ccn - i;
    }
    int Max2 = 0, pp = 0;
    for (int i = 0; i < cnt; i++) {
      if (CC[ccn - i - 1] < JA[cnt - i - 1]) {
        pp = 1;
        break;
      }
    }
    if (pp == 0) {
      for (int i = 0; i < ccn; i++) Max2 += CC[i];
      for (int i = 0; i < cnt; i++) Max2 -= JA[i];
    }
    printf("%d\n", max(max(Max, Max1), Max2));
  }
  return 0;
}
