#include <bits/stdc++.h>
using namespace std;
long long n, m, attCnt, defCnt;
long long att[102], def[102], ciel[102];
long long dp[102][102][102][2];
long long f(long long cid, long long aid, long long did, long long win) {
  if (cid == m) {
    if (win) {
      if (aid + did == n)
        return 0;
      else
        return -1e10;
    }
    return 0;
  }
  long long &ret = dp[cid][aid][did][win];
  if (~ret) return ret;
  ret = max(f(cid + 1, aid, did, win), ciel[cid] + f(cid + 1, aid, did, 1));
  if (aid < attCnt && att[aid] <= ciel[cid])
    ret = max(ret, ciel[cid] - att[aid] + f(cid + 1, aid + 1, did, win));
  if (did < defCnt && def[did] < ciel[cid])
    ret = max(ret, f(cid + 1, aid, did + 1, win));
  return ret;
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s[0] == 'A')
      cin >> att[attCnt++];
    else
      cin >> def[defCnt++];
  }
  for (long long i = 0; i < m; i++) cin >> ciel[i];
  sort(att, att + attCnt);
  sort(def, def + defCnt);
  sort(ciel, ciel + m);
  memset(dp, -1, sizeof(dp));
  cout << f(0, 0, 0, 0) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
