#include <bits/stdc++.h>
using namespace std;
int n, m, n1, n2;
int a1[107], a2[107];
int bb[107];
multimap<int, int> b;
int ans;
bool check() {
  int i;
  multimap<int, int>::iterator iter;
  for (i = 0; i < n2; ++i) {
    iter = b.upper_bound(a2[i]);
    if (iter == b.end()) return false;
    b.erase(iter);
  }
  for (i = 0; i < n1; ++i) {
    iter = b.lower_bound(a1[i]);
    if (iter == b.end()) return false;
    b.erase(iter);
  }
  b.clear();
  for (i = 0; i < m; ++i) b.insert(pair<int, int>(bb[i], bb[i]));
  return true;
}
int main() {
  int i, k, x, w;
  char cc[107];
  multimap<int, int>::iterator iter;
  scanf("%d%d", &n, &m);
  n1 = n2 = 0;
  for (i = 0; i < n; ++i) {
    scanf("%s", cc);
    scanf("%d", &x);
    if (cc[0] == 'A') {
      a1[n1++] = x;
    } else {
      a2[n2++] = x;
    }
  }
  sort(a1, a1 + n1);
  sort(a2, a2 + n2);
  b.clear();
  for (i = 0; i < m; ++i) {
    scanf("%d", &x);
    bb[i] = x;
    b.insert(pair<int, int>(x, x));
  }
  sort(bb, bb + m);
  ans = 0;
  if (check()) {
    for (i = 0; i < n2; ++i) {
      iter = b.upper_bound(a2[i]);
      b.erase(iter);
    }
    for (iter = b.begin(); iter != b.end(); ++iter) {
      ans += iter->second;
    }
    for (i = 0; i < n1; ++i) ans -= a1[i];
  }
  for (k = 0; k < n1; ++k) {
    for (i = m - 1; i >= m - k; --i) {
      if (i < 0) break;
      if (bb[i] < a1[m - i - 1]) break;
    }
    if (i >= m - k) break;
    w = 0;
    for (i = 0; i < k; ++i) w -= a1[i];
    for (i = m - 1; i >= m - k; --i) w += bb[i];
    if (w > ans) ans = w;
  }
  w = 0;
  for (i = 0; i < n1; ++i) {
    if (bb[m - i - 1] >= a1[i])
      w += bb[m - i - 1] - a1[i];
    else
      break;
  }
  if (w > ans) ans = w;
  cout << ans << endl;
  return 0;
}
