#include <bits/stdc++.h>
using namespace std;
int n, m, i, j;
char s[10];
vector<int> atk, def, celi, rem;
bool used[105];
int main() {
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    int x;
    scanf("%s%d", s, &x);
    if (s[0] == 'A')
      atk.push_back(x);
    else
      def.push_back(x);
  }
  for (i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    celi.push_back(x);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(celi.begin(), celi.end());
  int v = min(atk.size(), celi.size());
  int res = 0;
  for (i = 1; i <= v; i++) {
    int s = 0;
    bool flag = 1;
    for (j = 0; j < i; j++) {
      s += celi[celi.size() - (i - j)] - atk[j];
      if (celi[celi.size() - (i - j)] < atk[j]) flag = 0;
    }
    if (flag) res = max(res, s);
  }
  int p = 0;
  bool flag = 1;
  for (i = 0; i < def.size(); i++) {
    while (p < celi.size() && celi[p] <= def[i]) p++;
    if (p >= celi.size())
      flag = 0;
    else {
      used[p] = 1;
      p++;
    }
  }
  if (flag) {
    int tot = 0;
    vector<int> rem;
    for (i = 0; i < celi.size(); i++) {
      if (!used[i]) {
        rem.push_back(celi[i]);
        tot += celi[i];
      }
    }
    if (rem.size() >= atk.size()) {
      int s = 0;
      int s1 = 0;
      bool flag = 1;
      for (i = 0; i < atk.size(); i++) {
        s += rem[rem.size() - (atk.size() - i)] - atk[i];
        if (rem[rem.size() - (atk.size() - i)] < atk[i]) flag = 0;
        s1 += rem[rem.size() - (atk.size() - i)];
      }
      if (flag) res = max(res, s + (tot - s1));
    }
  }
  printf("%d\n", res);
}
