#include <bits/stdc++.h>
using namespace std;
struct card {
  int p;
  string second;
  card(int _p, string _s) { p = _p, second = _s; }
  bool operator<(const card &c) const {
    if (second == "ATK" && c.second == "DEF") return true;
    if (second == "DEF" && c.second == "ATK") return false;
    return p < c.p;
  }
};
int solve(vector<int> &troops, vector<int> &atk, vector<int> &def, bool all) {
  int ret = 0;
  multiset<int> curr(troops.begin(), troops.end());
  for (int i : def) {
    multiset<int>::iterator it = curr.lower_bound(i + 1);
    if (it == curr.end()) return 0;
    curr.erase(it);
  }
  for (int i = atk.size() - 1; i >= 0; i--) {
    if (*curr.rbegin() < atk[i]) return 0;
    ret += *curr.rbegin();
    ret -= atk[i];
    multiset<int>::iterator it = curr.end();
    it--;
    curr.erase(it);
  }
  if (all) {
    while (!curr.empty()) ret += *curr.begin(), curr.erase(curr.begin());
  }
  return ret;
}
int main() {
  int x, n, m;
  cin >> n >> m;
  vector<card> v;
  for (int i = 1; i <= n; i++) {
    string second;
    cin >> second >> x;
    v.push_back(card(x, second));
  }
  vector<int> vm(m);
  int ans = 0, sumEnemy = 0;
  for (int i = 0; i < m; i++) cin >> vm[i];
  sort(v.begin(), v.end());
  vector<int> atk, def;
  for (int i = 0; i < min(n, m); i++) {
    if (v[i].second == "ATK")
      atk.push_back(v[i].p);
    else
      def.push_back(v[i].p);
    ans = max(ans, solve(vm, atk, def, i == n - 1));
  }
  printf("%d", ans);
  return 0;
}
