#include <bits/stdc++.h>
const int maxn = 101;
const int maxc = 8001;
int n, m, i, j, k, ans, sum, tmp, sla[maxc], sld[maxc], sl[maxc], la[maxn],
    ld[maxn], l[maxn];
char s[4];
int main() {
  std::cin >> m >> n;
  std::cin.ignore();
  for (i = 1; i <= m; i++) {
    std::cin >> s;
    std::cin >> j;
    if (s[0] == 'A')
      sla[j]++;
    else
      sld[j]++;
    std::cin.ignore();
  }
  for (i = 0; i < maxc; i++) {
    for (j = 1; j <= sla[i]; j++) la[++la[0]] = i;
    for (j = 1; j <= sld[i]; j++) ld[++ld[0]] = i;
  }
  for (i = 1; i <= n; i++) {
    std::cin >> j;
    sum += j;
    sl[j]++;
  }
  for (i = 0; i <= maxc; i++)
    for (j = 1; j <= sl[i]; j++) l[++l[0]] = i;
  for (k = 1; k <= la[0]; k++) {
    tmp = 0;
    for (i = n, j = (n <= k) ? n : k; j > 0; i--, j--)
      if (l[i] > la[j]) tmp += l[i] - la[j];
    if (ans < tmp) ans = tmp;
  }
  j = 0;
  for (i = 1; i <= ld[0]; i++) {
    j++;
    while (j <= n && ld[i] >= l[j]) j++;
    if (j == n + 1) break;
    sum -= l[j];
    l[j] = -1;
  }
  if (j <= n && n > m) {
    j = n + 1;
    for (i = la[0]; i >= 1; i--) {
      j--;
      while (j >= 1 && (l[j] == -1 || l[j] < la[i])) j--;
      if (j == 0) break;
      sum -= la[i];
    }
    if (j > 0 && sum > ans) ans = sum;
  }
  std::cout << ans;
  return 0;
}
