#include <bits/stdc++.h>
using namespace std;
vector<int> acs, dcs, mcs;
int try1() {
  int an = ((int)(acs).size());
  int dn = ((int)(dcs).size());
  int n = an + dn;
  int m = ((int)(mcs).size());
  if (n > m) return 0;
  vector<vector<int> > a(n + 1, vector<int>(m + 1));
  for (int i = 0; i < int(m); i++)
    for (int j = 0; j < int(an); j++)
      a[j + 1][i + 1] = (mcs[i] >= acs[j]) ? 0 : 1000000;
  for (int i = 0; i < int(m); i++)
    for (int j = 0; j < int(dn); j++)
      a[j + an + 1][i + 1] = (mcs[i] > dcs[j]) ? mcs[i] - dcs[j] : 1000000;
  constexpr int INF = 2000000;
  vector<int> u(n + 1), v(m + 1), p(m + 1), way(m + 1);
  for (int i = 1; i <= n; ++i) {
    p[0] = i;
    int j0 = 0;
    vector<int> minv(m + 1, INF);
    vector<char> used(m + 1, false);
    do {
      used[j0] = true;
      int i0 = p[j0], delta = INF, j1;
      for (int j = 1; j <= m; ++j)
        if (!used[j]) {
          int cur = a[i0][j] - u[i0] - v[j];
          if (cur < minv[j]) minv[j] = cur, way[j] = j0;
          if (minv[j] < delta) delta = minv[j], j1 = j;
        }
      for (int j = 0; j <= m; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      int j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
  }
  int cost = -v[0];
  if (cost >= 1000000) return 0;
  int tot = 0;
  for (int j = 0; j < int(m); j++) tot += mcs[j];
  for (int j = 0; j < int(an); j++) tot -= acs[j];
  for (int j = 0; j < int(dn); j++) tot -= dcs[j];
  return tot - cost;
}
int try2() {
  int mi = 0, ai = 0;
  while (ai < ((int)(acs).size())) {
    while (mi < ((int)(mcs).size()) && mcs[mi] < acs[ai]) ++mi;
    if (mi >= ((int)(mcs).size())) break;
    ++ai;
    ++mi;
  }
  int ans = 0, ca = 0;
  for (int i = 0; i < int(ai); i++) {
    ca += mcs[((int)(mcs).size()) - 1 - i] - acs[i];
    ans = max(ans, ca);
  }
  return ans;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int n = 0; n < int(N); n++) {
    char tmp[4];
    int v;
    scanf(" %s %d", tmp, &v);
    if (tmp[0] == 'A')
      acs.push_back(v);
    else
      dcs.push_back(v);
  }
  for (int m = 0; m < int(M); m++) {
    int x;
    scanf("%d", &x);
    mcs.push_back(x);
  }
  sort(acs.begin(), acs.end());
  sort(mcs.begin(), mcs.end());
  printf("%d\n", max(try1(), try2()));
}
