#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-15;
const int maxN = 1 * 100 + 10, mod = (int)1e9 + 7;
vector<int> dj;
vector<int> aj;
vector<int> f;
int n, m, x, p, q;
string s;
long long s1, s2;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s >> x;
    if (s[0] == 'A')
      aj.push_back(x);
    else
      dj.push_back(x);
  }
  for (int i = 0; i < m; ++i) {
    cin >> x;
    f.push_back(x);
  }
  sort(aj.begin(), aj.end());
  sort(dj.begin(), dj.end());
  sort(f.begin(), f.end());
  p = aj.size();
  q = dj.size();
  int pt1 = 0;
  s1 = 0;
  for (int i = 0; i < p; ++i) {
    if (m - i - 1 >= 0 && f[m - i - 1] >= aj[i])
      s1 += f[m - i - 1] - aj[i];
    else
      break;
  }
  bool v = 1;
  for (int i = 0; i < q; ++i) {
    if (pt1 >= m) {
      v = 0;
      break;
    }
    if (dj[i] < f[pt1])
      f[pt1] = -1;
    else
      i--;
    pt1++;
  }
  pt1 = 0;
  for (int i = 0; i < p; ++i) {
    if (pt1 >= m) {
      v = 0;
      break;
    }
    if (aj[i] <= f[pt1])
      ;
    else
      i--;
    pt1++;
  }
  s2 = 0;
  if (v) {
    for (int i = 0; i < m; ++i)
      if (f[i] != -1) s2 += f[i];
    for (int i = 0; i < p; ++i) s2 -= aj[i];
  }
  cout << max(s1, s2);
  return 0;
}
