#include <bits/stdc++.h>
static long long other_try(std::vector<int>& attacking,
                           const std::vector<int>& attack_pos,
                           const std::vector<int>& def_pos) {
  std::sort(attacking.begin(), attacking.end());
  long long ret = 0;
  for (int i = 0; i < def_pos.size(); i++) {
    if (attacking.size() == 0) return ret;
    const auto loc =
        std::upper_bound(attacking.begin(), attacking.end(), def_pos[i]);
    if (loc == attacking.end()) return ret;
    attacking.erase(loc);
  }
  for (int i = 0; i < attack_pos.size(); i++) {
    const auto loc =
        std::lower_bound(attacking.begin(), attacking.end(), attack_pos[i]);
    if (loc == attacking.end()) return ret;
    ret += (*loc - attack_pos[i]);
    attacking.erase(loc);
  }
  for (int i = 0; i < attacking.size(); i++) ret += attacking[i];
  return ret;
}
int main(int argc, const char** argv) {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  std::vector<int> attack_pos, def_pos;
  for (int i = 0; i < n; i++) {
    std::string type;
    int strength;
    std::cin >> type >> strength;
    if (type == "ATK")
      attack_pos.push_back(strength);
    else
      def_pos.push_back(strength);
  }
  std::vector<int> attacking(m);
  for (int i = 0; i < m; i++) std::cin >> attacking[i];
  std::vector<int> original = attacking;
  std::sort(attacking.begin(), attacking.end(), std::greater<int>());
  std::sort(attack_pos.begin(), attack_pos.end());
  std::sort(def_pos.begin(), def_pos.end());
  long long damage = 0;
  const int lim = std::min(attacking.size(), attack_pos.size());
  for (int i = 0; i < lim; i++) {
    if (attacking[i] >= attack_pos[i])
      damage += attacking[i] - attack_pos[i];
    else
      goto finish;
  }
  attacking.erase(attacking.begin(), attacking.begin() + lim);
  std::reverse(attacking.begin(), attacking.end());
  for (int i = 0; i < def_pos.size(); i++) {
    if (attacking.size() == 0) goto finish;
    const auto loc =
        std::upper_bound(attacking.begin(), attacking.end(), def_pos[i]);
    if (loc == attacking.end()) goto finish;
    attacking.erase(loc);
  }
  for (int i = 0; i < attacking.size(); i++) damage += attacking[i];
finish:
  std::cout << std::max(damage, other_try(original, attack_pos, def_pos))
            << '\n';
  return EXIT_SUCCESS;
}
