#include <bits/stdc++.h>
using namespace std;
int best_attack(vector<int> attacker, vector<int> attacked) {
  int ans = 0;
  int attacker_n = attacker.size();
  int card_n = attacked.size();
  sort(attacker.begin(), attacker.end());
  sort(attacked.begin(), attacked.end());
  for (int n = 1; n <= card_n; ++n) {
    int lost = 0;
    for (int i = 1; i <= n; ++i) {
      if (attacker_n - i >= 0 && attacker[attacker_n - i] >= attacked[n - i]) {
        lost += attacker[attacker_n - i] - attacked[n - i];
      }
    }
    if (lost > ans) {
      ans = lost;
    }
  }
  return ans;
}
int best_over_attack(vector<int> attacker, vector<int> attacked) {
  int ans = 0;
  int attacker_n = attacker.size();
  int card_n = attacked.size();
  sort(attacker.begin(), attacker.end());
  sort(attacked.begin(), attacked.end());
  for (int i = 1; i <= card_n; ++i) {
    if (attacker[attacker_n - i] >= attacked[card_n - i]) {
      ans += attacker[attacker_n - i] - attacked[card_n - i];
    } else {
      return -1;
    }
  }
  for (int i = 0; i < attacker_n - card_n; ++i) {
    ans += attacker[i];
  }
  return ans;
}
int main() {
  int an, bn;
  scanf("%d%d", &an, &bn);
  vector<int> attacked_atk;
  vector<int> attacked_def;
  vector<int> attacker(bn);
  for (int i = 0; i < an; ++i) {
    char type[4];
    int str;
    scanf("%s%d", type, &str);
    if (type[0] == 'A') {
      attacked_atk.push_back(str);
    } else {
      attacked_def.push_back(str);
    }
  }
  for (int i = 0; i < bn; ++i) {
    scanf("%d", &attacker[i]);
  }
  int ans = best_attack(attacker, attacked_atk);
  if (bn > an) {
    sort(attacker.begin(), attacker.end());
    bool destroyable = true;
    for (auto def : attacked_def) {
      auto finded = lower_bound(attacker.begin(), attacker.end(), def + 1);
      if (finded != attacker.end()) {
        attacker.erase(finded);
      } else {
        destroyable = false;
        break;
      }
    }
    if (destroyable) {
      int ans2 = best_over_attack(attacker, attacked_atk);
      if (ans2 >= 0 && ans2 > ans) {
        ans = ans2;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
