#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double eps = 1e-7;
const int MAXN = 1e5 + 10;
int dx[] = {1, 0, 0, -1, -1, -1, 1, 1};
int dy[] = {0, 1, -1, 0, 1, -1, 1, -1};
vector<int> v1, v2, v3;
int dp[101][101][101][2];
int fun(int attack, int def, int fox, bool s) {
  if (fox == ((int)((v3).size()))) {
    if (s == 1) {
      if (attack == ((int)((v1).size())) && def == ((int)((v2).size())))
        return 0;
      else
        return -1e8;
    }
    return 0;
  }
  int &ret = dp[attack][def][fox][s];
  if (ret != -1) return ret;
  ret = 0;
  ret = fun(attack, def, fox + 1, s);
  ret = max(ret, fun(attack, def, fox + 1, 1) + v3[fox]);
  if (attack < ((int)((v1).size())) && v3[fox] >= v1[attack])
    ret = max(ret, fun(attack + 1, def, fox + 1, s) + v3[fox] - v1[attack]);
  if (def < ((int)((v2).size())) && v3[fox] > v2[def])
    ret = max(ret, fun(attack, def + 1, fox + 1, s));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int b;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> b;
    if (s[0] == 'A')
      v1.push_back(b);
    else
      v2.push_back(b);
  }
  for (int j = 0; j < m; j++) {
    cin >> b;
    v3.push_back(b);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  sort(v3.begin(), v3.end());
  memset(dp, -1, sizeof(dp));
  cout << fun(0, 0, 0, 0) << endl;
}
