#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> ni[n];
  int mi[m];
  string s;
  int tm;
  for (int i = 0; i < n; i++) {
    cin >> s >> tm;
    if (s[0] == 'A')
      ni[i] = make_pair(1, tm);
    else
      ni[i] = make_pair(0, tm);
  }
  for (int i = 0; i < m; i++) scanf("%d", &mi[i]);
  ;
  bool mii[m];
  for (int i = 0; i < m; i++) mii[i] = true;
  sort(ni, ni + n);
  sort(mi, mi + m);
  bool yo = true;
  int su = 0;
  for (int i = 0; i < n; i++) {
    if (ni[i].first == 1) {
      int att = 10000000, ati = -1;
      for (int j = 0; j < m; j++) {
        if (mi[j] >= ni[i].second && mi[j] < att && mii[j])
          att = mi[j], ati = j;
      }
      if (ati == -1)
        yo = false;
      else {
        mii[ati] = false;
        su -= ni[i].second;
      }
    } else {
      int att = 10000000, ati = -1;
      for (int j = 0; j < m; j++) {
        if (mi[j] > ni[i].second && mi[j] < att && mii[j]) att = mi[j], ati = j;
      }
      if (ati == -1)
        yo = false;
      else {
        mii[ati] = false;
        su -= mi[ati];
      }
    }
  }
  int ans1 = 0;
  for (int i = 0; i < m; i++) ans1 += mi[i];
  if (yo)
    ans1 += su;
  else
    ans1 = 0;
  bool nii[n];
  for (int i = 0; i < n; i++) nii[i] = true;
  int ans2 = 0;
  for (int i = m - 1; i >= 0; i--) {
    int att = 10000000, ati = -1;
    for (int j = 0; j < n; j++) {
      if (ni[j].first == 1 && mi[i] >= ni[j].second && mi[i] < att && nii[j])
        att = ni[j].second, ati = j;
    }
    if (ati != -1) {
      nii[ati] = false;
      ans2 += mi[i] - att;
    }
  }
  cout << max(ans1, ans2) << endl;
}
