#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, p, B[8005], DEF[105], ATT[105], MINE[105], A, D, N, SOL1, SOL2,
    ok;
char S[100];
bool cmp1(int a, int b) { return a > b; }
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s %d", S, &p);
    if (S[0] == 'A')
      ATT[++A] = p;
    else
      DEF[++D] = p;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &p);
    MINE[++N] = p;
    B[p]++;
  }
  sort(ATT + 1, ATT + A + 1);
  sort(MINE + 1, MINE + N + 1, cmp1);
  for (i = 1, j = 1; i <= A && j <= N; i++, j++) {
    if (MINE[j] < ATT[i]) break;
    SOL1 += MINE[j] - ATT[i];
  }
  if (m < n) {
    printf("%d\n", SOL1);
    return 0;
  }
  sort(DEF + 1, DEF + D + 1);
  for (i = 1; i <= D; i++) {
    ok = 0;
    for (j = DEF[i] + 1; j <= 8000; j++)
      if (B[j]) {
        B[j]--;
        ok = 1;
        break;
      }
    if (!ok) {
      printf("%d\n", SOL1);
      return 0;
    }
  }
  sort(ATT + 1, ATT + A + 1);
  for (i = 1; i <= A; i++) {
    ok = 0;
    for (j = ATT[i]; j <= 8000; j++)
      if (B[j]) {
        B[j]--;
        ok = 1;
        break;
      }
    if (!ok) {
      printf("%d\n", SOL1);
      return 0;
    } else
      SOL2 += j - ATT[i];
  }
  for (i = 1; i <= 8000; i++) SOL2 += i * B[i];
  printf("%d\n", max(SOL1, SOL2));
  return 0;
}
